Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int buttonPin1 = 2; // the number of the pushbutton pin
- const int buttonPin2 = 3;
- const int ledPin = 13; // the number of the LED pin
- // variables will change:
- int buttonPresses=0;
- int buttonState = 0; // variable for reading the pushbutton status
- int ledState = LOW; // ledState used to set the LED
- long previousMillis = 0;
- long interval = 100;
- void setup() {
- // initialize the LED pin as an output:
- pinMode(ledPin, OUTPUT);
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin1, INPUT);
- pinMode(buttonPin2, INPUT);
- }
- void loop(){
- // read the state of the pushbutton value:
- buttonState = digitalRead(buttonPin1);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState == HIGH) buttonPresses++;
- if(buttonPresses>=3) {
- unsigned long currentMillis = millis();
- if(currentMillis - previousMillis > interval) {
- // save the last time you blinked the LED
- previousMillis = currentMillis;
- // if the LED is off turn it on and vice-versa:
- if (ledState == LOW)
- ledState = HIGH;
- else
- ledState = LOW;
- // set the LED with the ledState of the variable:
- digitalWrite(ledPin, ledState);
- }
- }
- buttonState = digitalRead(buttonPin2);
- if (buttonState == HIGH) { buttonPresses=0;
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement