int buttonPin = 2;
int LEDPin = 13;
bool LEDOn = true;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT);
pinMode(LEDPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
bool buttonPressed = digitalRead(buttonPin);
if (buttonPressed){
if (LEDOn==true){
digitalWrite(LEDPin, LOW);
LEDOn = false;
} else {
digitalWrite(LEDPin, HIGH);
LEDOn = true;
}
}
}