#define BTN_PIN 2
const int LED_PIN = 13;
bool ledState = false; // status LED
bool lastButton = HIGH; // status terakhir tombol (HIGH karena pakai INPUT_PULLUP)
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int button = digitalRead(BTN_PIN);
// deteksi perubahan (tombol ditekan)
if (button == LOW && lastButton == HIGH) {
// ubah status LED
ledState = !ledState;
digitalWrite(LED_PIN, ledState);
delay(200); // debounce sederhana
}
lastButton = button;
}