Advertisement
Guest User

Arduino Code

a guest
Aug 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1.  
  2. const int LED = 7;
  3. const int MOTION = 5;
  4. int currentLight1;
  5. int lightState1;
  6. const int HOUR = 3600000;
  7.  
  8. unsigned long lastTimeOn = 0;//last time input was toggled
  9. unsigned long lightDelay =HOUR;//debounce time
  10. void setup() {
  11. pinMode(LED, OUTPUT);
  12. pinMode(MOTION, INPUT);
  13. currentLight1 = LOW;
  14. lightState1 = LOW;
  15. Serial.begin(9600);
  16. }
  17.  
  18. void loop() {
  19. int sensor1 = digitalRead(MOTION);
  20. Serial.write("hi");
  21. if (sensor1 == HIGH && currentLight1 == LOW) {
  22. lightState1 = HIGH;
  23. Serial.write("hi");
  24. currentLight1 = HIGH;
  25. lastTimeOn = millis();
  26. }
  27.  
  28. if((millis() - lastTimeOn) > lightDelay) {
  29. if(lightState1 == HIGH) {
  30. currentLight1 = LOW;
  31. lightState1 = LOW;
  32. }
  33. }
  34. digitalWrite(LED, lightState1);
  35.  
  36.  
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement