const int buttonPin = PA0; // Connect a button between PA0 and GND
const int ledPin = PA5; // On-board LED
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Use the MCU's internal pull-up resistor
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Serial.println("Button Debugger Started!");
}
void loop() {
int buttonState = digitalRead(buttonPin);
// Print only when the state changes
if (buttonState == LOW) { // Button is pressed (pulled to GND)
digitalWrite(ledPin, HIGH);
Serial.println("EVENT: Button PRESSED");
} else {
digitalWrite(ledPin, LOW);
Serial.println("EVENT: Button RELEASED");
}
delay(100); // Small delay to debounce and avoid spamming the serial monitor
}