/*
1. Hubungkan anoda LED ke pin digital (pin 13) pada papan Arduino.
2. Hubungkan katoda LED ke resistansi (200 ohm) dan ke ground (GND) papan Arduino.
3. Hubungkan salah satu kaki tombol tekan ke pin digital (pin 2).
4. Hubungkan kaki tombol tekan lainnya ke ground (GND) papan Arduino.
*/
// Define variables
int buttonPin = 2;
int ledPin = 13;
bool buttonState = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed (buttonState is LOW when pressed due to pull-up resistor)
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH); // Turn LED on.
} else {
digitalWrite(ledPin, LOW); // Turn LED off.
}
}