Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LED = 7;
- const int MOTION = 5;
- int currentLight1;
- int lightState1;
- const int HOUR = 3600000;
- unsigned long lastTimeOn = 0;//last time input was toggled
- unsigned long lightDelay =HOUR;//debounce time
- void setup() {
- pinMode(LED, OUTPUT);
- pinMode(MOTION, INPUT);
- currentLight1 = LOW;
- lightState1 = LOW;
- Serial.begin(9600);
- }
- void loop() {
- int sensor1 = digitalRead(MOTION);
- Serial.write("hi");
- if (sensor1 == HIGH && currentLight1 == LOW) {
- lightState1 = HIGH;
- Serial.write("hi");
- currentLight1 = HIGH;
- lastTimeOn = millis();
- }
- if((millis() - lastTimeOn) > lightDelay) {
- if(lightState1 == HIGH) {
- currentLight1 = LOW;
- lightState1 = LOW;
- }
- }
- digitalWrite(LED, lightState1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement