const int buttonPin = 2; // Button pin from SAMD11C14A const int ledPin = 4; // LED pin from SAMD11C14A int ledState = LOW; // Current LED state bool previousButtonState = HIGH; // Previous button state, assuming pull-up void setup() { pinMode(ledPin, OUTPUT); // Initialize LED pin as output pinMode(buttonPin, INPUT_PULLUP); // Initialize button pin as input with pull-up resistor } void loop() { bool currentButtonState = digitalRead(buttonPin); if (currentButtonState == LOW && previousButtonState == HIGH) { // Button was pressed ledState = !ledState; // Toggle the LED state digitalWrite(ledPin, ledState); // Set the LED to the new state } previousButtonState = currentButtonState; // Update the previous button state }