Thanks for your help everybody. 6v6gt i tryied the : if(millis() >= off1 || digitalRead(buttonUp) == LOW ) and as you said there are problems with the buttons then i put the other code as below but when i push the button after the first push,it doesn't turn off the led1Up.
I am a little confused(to be specific a lot of confused).
int led1Up = 2;
int led2Down = 3;
int buttonUp = 4;
int buttonDown = 6;
void setup()
{
pinMode(buttonUp, INPUT_PULLUP);
pinMode(led1Up, OUTPUT);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(led2Down, OUTPUT);
}
long off1 = 0;
long off2 = 0;
void loop()
{
if( (digitalRead(led1Up) == LOW )&&(digitalRead(led2Down) == LOW ) && (digitalRead(buttonUp) == LOW)&& (digitalRead(buttonDown) == HIGH) ) //if LED is off and button is pressed [low because it has pullup resistor]
{
digitalWrite(led1Up, HIGH);
off1 = millis() + 5000; //store var of now + 5 seconds
}
if(digitalRead(led1Up) == HIGH ) //if led is on
if(millis() >= off1 || ( digitalRead(buttonUp) == LOW && off1 - millis() > 250 && off1 - millis() < 5000 ) ) //see if it's time to turn off LED
{
digitalWrite(led1Up, LOW); //it's time. this also re-enables the button
}
//for second button
if( (digitalRead(led2Down) == LOW )&&(digitalRead(led1Up) == LOW ) && (digitalRead(buttonDown) == LOW) && (digitalRead(buttonUp) == HIGH) ) //if LED is off and button is pressed [low because it has pullup resistor]
{
digitalWrite(led2Down, HIGH);
off2 = millis() + 5000; //store var of now + 5 seconds
}
if(digitalRead(led2Down) == HIGH) //if led is on
if(millis() >= off2) //see if it's time to turn off LED
{
digitalWrite(led2Down, LOW); //it's time. this also re-enables the button
}
}