const int ledPin = 9; const int buttonPin = 5; int ledState = LOW; void setup() { // put your setup code here, to run once: pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); // start with led off digitalWrite(ledPin, ledState); } void loop() { int reading = digitalRead(buttonPin); // if button is pressed and led off, then turn led on if (reading == LOW and ledState == LOW) { ledState = HIGH; digitalWrite(ledPin, HIGH); // if button is pressed and led on, then turn led off } else if (reading == LOW and ledState == HIGH) { ledState = LOW; digitalWrite(ledPin, LOW); } }