Advertisement
Guest User

Untitled

a guest
May 25th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. const int buttonPin1 = 2; // the number of the pushbutton pin
  2. const int buttonPin2 = 3;
  3. const int ledPin = 13; // the number of the LED pin
  4.  
  5.  
  6. // variables will change:
  7. int buttonPresses=0;
  8. int buttonState = 0; // variable for reading the pushbutton status
  9. int ledState = LOW; // ledState used to set the LED
  10. long previousMillis = 0;
  11. long interval = 100;
  12. void setup() {
  13. // initialize the LED pin as an output:
  14. pinMode(ledPin, OUTPUT);
  15. // initialize the pushbutton pin as an input:
  16. pinMode(buttonPin1, INPUT);
  17. pinMode(buttonPin2, INPUT);
  18. }
  19.  
  20. void loop(){
  21. // read the state of the pushbutton value:
  22. buttonState = digitalRead(buttonPin1);
  23.  
  24. // check if the pushbutton is pressed.
  25. // if it is, the buttonState is HIGH:
  26. if (buttonState == HIGH) buttonPresses++;
  27. if(buttonPresses>=3) {
  28. unsigned long currentMillis = millis();
  29. if(currentMillis - previousMillis > interval) {
  30. // save the last time you blinked the LED
  31. previousMillis = currentMillis;
  32.  
  33. // if the LED is off turn it on and vice-versa:
  34. if (ledState == LOW)
  35. ledState = HIGH;
  36. else
  37. ledState = LOW;
  38.  
  39. // set the LED with the ledState of the variable:
  40. digitalWrite(ledPin, ledState);
  41. }
  42. }
  43.  
  44.  
  45. buttonState = digitalRead(buttonPin2);
  46. if (buttonState == HIGH) { buttonPresses=0;
  47. digitalWrite(ledPin, LOW);
  48. }
  49.  
  50.  
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement