Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Pin =8;
- int ledPin = 13;
- boolean lastButton = LOW;
- boolean currentButton = LOW;
- boolean ledOn = false;
- void setup()
- {
- pinMode(Pin, INPUT);
- pinMode(ledPin, OUTPUT);
- }
- boolean debounce(boolean last)
- {
- boolean current =digitalRead(Pin);
- if (last != current)
- {
- delay(5);
- current = digitalRead(Pin);
- }
- return current;
- }
- void loop()
- {
- currentButton = debounce(lastButton);
- if (lastButton == HIGH && currentButton == HIGH)
- {
- ledOn = !ledOn;
- }
- lastButton = currentButton;
- digitalWrite(ledPin, ledOn);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement