Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pinButton = 7;
- int LED = 8;
- int stateLED = LOW;
- int stateButton;
- int previous = LOW;
- long time = 0;
- long debounce = 200;
- void setup() {
- pinMode(pinButton, INPUT);
- pinMode(LED, OUTPUT);
- }
- void loop() {
- stateButton = digitalRead(pinButton);
- if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
- if(stateLED == HIGH){
- stateLED = LOW;
- } else {
- stateLED = HIGH;
- }
- time = millis();
- }
- digitalWrite(LED, stateLED);
- previous == stateButton;
- }
Add Comment
Please, Sign In to add comment