const int buttonPin = 3;
const int ledPin = 8;
const int ledPin1 = 9;
#define waktu 5
//-------------------------------
int initial = 0;
int oldstate = 0;
int buttonstate = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
relay();
}
void relay(){
buttonstate = digitalRead(buttonPin);
if(buttonstate == LOW){
delay(waktu);
buttonstate = digitalRead(buttonPin);
if(buttonstate == HIGH){
initial = oldstate + 1;
}
}else{
}
switch (initial){
case 1:
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, LOW);
oldstate = initial;
break;
case 2:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
oldstate = 0;
break;
}
}