countDecko

Untitled

Sep 20th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. int lastMillis = -1;
  2. int currentMillis = -1;
  3. int buttonState = -1;
  4. int buttonLastState = -1;
  5. int button = 3;
  6. int led = 4;
  7.  
  8. void setup() {
  9. // put your setup code here, to run once:
  10. pinMode(button, INPUT_PULLUP);
  11. }
  12.  
  13. void loop() {
  14. // put your main code here, to run repeatedly:
  15. buttonState = digitalRead(button);
  16. currentMillis = millis();
  17.  
  18. if(buttonState != buttonLastState){
  19. if(buttonState == LOW){
  20. digitalWrite(led, HIGH);
  21. lastMillis = millis();
  22. }
  23. }
  24.  
  25. if(currentMillis - lastMillis > 2000){
  26. digitalWrite(led, LOW);
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment