HW 6
PIR AND LIGHT SENSORS, BLINK MODE INCLUDED WITH COUNT boolean lastPIR = LOW; boolean currentPIR = LOW; const int LED = 10; const int PIR = 2; const int LIGHT = 0; int val = 0; int count = 0; int x = 0; boolean debounce(boolean last) { boolean current = digitalRead(PIR); //Read the button state if (last != current) //if it's different... { delay(5); //wait 5ms current = digitalRead(PIR); //read it again } return current; //return the current value } \ void setup() { pinMode (LED, OUTPUT); pinMode (PIR, INPUT); Serial.begin(9600); } void loop() { val = analogRead(LIGHT); currentPIR = debounce(lastPIR); if (digitalRead(PIR) == HIGH) { digitalWrite (LED, HIGH); if (lastPIR == LOW && currentPIR == HIGH) count ++; } else if (val > 400 && digitalRead(PIR) == LOW) { ...
Comments
Post a Comment