was it something like this that you were looking for?
/*
CIRCUIT:
* led to Arduino pin 4
* button1 to Arduino pin 8
* button2 to Arduino pin 9
(using a 10k pull-up resistor for both buttons)
*/
// VARIABLES
int led = 4;
boolean ledState = LOW;
long ledStart;
int interval = 2000;
int but1 = 8;
int but1State;
int lastBut1State = HIGH;
int but2 = 9;
int but2State;
int lastBut2State = HIGH;
void setup() {
pinMode(led,OUTPUT);
pinMode(but1,INPUT);
pinMode(but2,INPUT);
}
void loop() {
// read buttons
but1State = digitalRead(but1);
but2State = digitalRead(but2);
// if button1 is pressed
if(but1State != lastBut1State && but1State == LOW) {
ledState = HIGH; // set led state to HIGH
ledStart = millis(); // save starting time
}
// if button2 is pressed
if(but2State != lastBut2State && but2State == LOW) {
ledState = LOW; // set led state to LOW
}
// check if 2 second have passed since led was turned on
if(millis() - ledStart >= interval){
ledState = LOW; // set led state to LOW
}
digitalWrite(led,ledState); // write the ledState
// update lastButton variables
lastBut1State = but1State;
lastBut2State = but2State;
}
i didn't try it, but give it a go and make any changes you need.
as you can see i am not using the delay() function. i am using a very useful technic to see if a set amount of time as gone by which you can learn how to use here:
Good lock!
=)