// set pin numbers
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 5; // the number of the LED pin
// variable for storing the pushbutton status
int NewbuttonState = 0;
int OldbuttonState = 0;
void setup() {
// initialize the pushbutton pin as an input
pinMode(buttonPin, INPUT);
// initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// inisalisasi serial
Serial.begin(115200); // 9600, 1200
}
void loop() {
// read the state of the pushbutton value
NewbuttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
if (NewbuttonState != OldbuttonState) {
if (NewbuttonState == HIGH) {
// turn LED on
Serial.println("the button is PUSHED");
digitalWrite(ledPin, HIGH);
} else {
// turn LED off
Serial.println("the button is RELEASED");
digitalWrite(ledPin, LOW);
}
OldbuttonState = NewbuttonState;
}
}