const int buttonPin = 2;
const int LEDPin = 26;
int Ledstate = LOW;
int lastButtonState;
int currentButtonstate;
void setup() {
Serial.begin(9600);
pinMode( buttonPin, INPUT_PULLUP);
pinMode(LEDPin, OUTPUT);
currentButtonstate = digitalRead(buttonPin);
}
void loop() {
lastButtonState = currentButtonstate;
currentButtonstate = digitalRead(buttonPin);
if(lastButtonState == HIGH && currentButtonstate == LOW) {
Serial.println("Tombol ditekan");
Ledstate =!Ledstate;
digitalWrite(LEDPin,Ledstate);
}
delay(100); // this speeds up the simulation
}