#define LED_PIN PC13
#define BUTTON_PIN PA0
bool ledState = false; // false = OFF
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 50; // milliseconds
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Button to GND
digitalWrite(LED_PIN, HIGH); // Start LED OFF (PC13 active low)
}
void loop() {
bool reading = digitalRead(BUTTON_PIN);
// Detect changes
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
// After debounce time, check if it was a press
if ((millis() - lastDebounceTime) > debounceDelay) {
if (lastButtonState == HIGH && reading == LOW) {
ledState = !ledState;
digitalWrite(LED_PIN, ledState ? LOW : HIGH); // Active low LED
}
}
lastButtonState = reading;
}