const int buttonPin = 15; // Pin tempat tombol push button terhubung
const int ledPin = 5; // Pin tempat LED terhubung
int buttonState = 0; // Variabel untuk menyimpan status tombol
int lastButtonState = 0; // Variabel untuk menyimpan status tombol sebelumnya
bool ledOn = false; // Variabel untuk menyimpan status LED
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT); // Aktifkan resistor pull-up internal
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
// Tombol ditekan, ubah status LED
ledOn = !ledOn;
digitalWrite(ledPin, ledOn ? HIGH : LOW); // Hidupkan atau matikan LED
}
delay(50); // Debouncing sederhana
}
lastButtonState = buttonState;
}