const int ledPin = 7;
const int buttonPin = 2;
int buttonState = 0;
int lastButtonState = 0;
bool ledOnOff = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
buttonPress();
}
void buttonPress() {
buttonState = digitalRead(buttonPin);
if ((buttonState == HIGH) && (lastButtonState == LOW)) {
ledOnOff = !ledOnOff;
digitalWrite(ledPin, ledOnOff ? LOW: HIGH);
}
lastButtonState = buttonState;
delay(10);
}