// Rogelio Cordoba 04/03/24 // Pin definitions const int buttonPin = 2; // The pin where the button is connected const int ledPin = 16; // The pin where the LED is connected // Variables int buttonState = 0; // Variable for storing the button state int lastButtonState = 0; // Variable for storing the previous button state void setup() { pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output pinMode(buttonPin, INPUT); // Initialize the button pin as an input } void loop() { // Read the state of the button buttonState = digitalRead(buttonPin); // Check if the button is pressed if (buttonState != lastButtonState) { // If the button is pressed if (buttonState == HIGH) { // Toggle the LED state digitalWrite(ledPin, !digitalRead(ledPin)); delay(50); // Debounce delay } } // Save the current button state for the next loop iteration lastButtonState = buttonState; }