#define LED 13 // the pin for the LED
#define LED 12 //defining LED 12 here makes the whole thing doesn't work..not sure how to define
#define BUTTON 7 // the input pin where the
// pushbutton is connected
int val = 0; // val will be used to store the state
// of the input pin
int old_val = 0; // this variable stores the previous
// value of "val"
int state = 0; // 0 = LED off and 1 = LED on
unsigned long startTime = 0;
void setup() {
pinMode(13, OUTPUT); // tell Arduino LED is an output
pinMode(7, INPUT); // and BUTTON is an input
}
void loop(){
val = digitalRead(7); // read input value and store it
// check if there was a transition
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
startTime = millis();
delay(10); }
old_val = val; // val is now old, let's store it
if (state == 0 && (millis() - startTime) < 10000) {
digitalWrite(13, LOW); // turn LED OFF
} else {
digitalWrite(13, HIGH);
}
if (state == 0 && (millis() - startTime) < 20000) {
digitalWrite(12, LOW); // turn LED OFF
} else {
digitalWrite(12, HIGH);
}}