Buttons as Inputs - 05/12/2021 6:00 PM
Code
//www.elegoo.com //2016.12.08 int ledPin = 5; int buttonApin = 9; bool buttonPressed = 0; byte leds = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonApin, INPUT_PULLUP); pinMode(buttonBpin, INPUT_PULLUP); } void loop() { if (digitalRead(buttonApin) == LOW) { if(!buttonPressed) { digitalWrite(ledPin, HIGH); buttonPressed = 1; }else{ digitalWrite(ledPin,LOW); buttonPressed = 0; } } }
Notice how I'm using a boolean variable called buttonPressed to track what the button did last.