Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // code is not verified to work. just illustrating some changes to be made.
- int delaytime = 2000;
- int switchpin = 8;
- int ledpin = 13;
- bool statechanged = false; // notice how this is different?
- bool lastbutton = LOW;
- bool currentButton = LOW;
- void setup()
- {
- pinMode(ledpin, OUTPUT);
- pinMode(switchpin, INPUT);
- }
- void loop()
- {
- currentButton = digitalRead(switchpin);
- if (currentButton == HIGH && lastbutton == LOW)
- {
- statechanged = true;
- lastbutton = HIGH;
- }
- else
- {
- lastbutton = currentButton; // calling digitalRead() like could have a problem if the pin's state changed since you last checked
- }
- digitalWrite(ledpin, HIGH);
- delay(delaytime);
- digitalWrite(ledpin, LOW);
- delay(delaytime);
- if ( statechanged == true && delaytime > 10)
- {
- delaytime = delaytime - 499;
- }
- else
- {
- delaytime = 2000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement