int btn1 = 6; // pins for buttons connected to Arduino int btn2 = 5; int bt1Val, bt2Val; // value is TRUE if button pressed, FALSE // if no press long btThresh = 100; // time between button presses is 1/10 of a second long lastBt1 = millis();// current system time long lastBt2 = millis(); int led1 = 11; // first LED void setup() { pinMode(btn1, INPUT); // set the button pins as INPUTS pinMode(btn2, INPUT); pinMode(led1, OUTPUT);// set the LED pins as OUTPUTS digitalWrite(led1, LOW);// turn OFF the LEDs Serial.begin(9600); } void loop() { // scan the buttons for presses bt1Val = digitalRead(btn1); bt2Val = digitalRead(btn2); if (bt1Val) { // if the button state is HIGH if (millis() - lastBt1 > btThresh) { // if the minimum of time has passed // since the last button 1 press digitalWrite(led1, HIGH); //turn LED1 ON Serial.println("activate"); lastBt1 = millis(); //reset for next button press } } if (bt2Val) { // if the button state is HIGH if (millis() - lastBt2 > btThresh) { // if the minimum of time has passed // since the last button 1 press digitalWrite(led1, LOW); //turn LED1 OFF lastBt2 = millis(); //reset for next button press } } delay(50); // slow down sketch a bit }