const int buttonPin = 6; // PORT D 2
const int ledPin = 7; // PORT D 7
// Variable to store the current state of the button
int buttonState = 0;
void setup() {
// Initialize the button pin as an input
pinMode(buttonPin, INPUT);
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the current state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH) {
// Wait for the button to be released
while (digitalRead(buttonPin) == HIGH) {
delay(50);
}
// Toggle the LED state
digitalWrite(ledPin, !digitalRead(ledPin));
}
}