Good morning or Good evening. PaulMurrayCbr is for domestic use of windows-doors electric shouters.Relays are 12v input and 230v 10A output.I will just put 2 extra 5v in order to control all the other from arduino(only for the master use).
Locally the shouters works from each room.So without the modification which we are trying to do, if i connect arduino with the current program,When i push the button up (from master) all the shouters go up until the expire of 5s for example(actually i will put 9s deadline). Also the buttonDown does not work(either i push it or not) until the led1up turns off.The same is the function when i push buttonDown.
Now i want to have a second choice which will allow me to turn the led1up off before the expire of the 5s sec by pushing the buttonUp again.Now if i push the buttonUp again after the first time nothing happens and the led1 stays on until the expire of time.I believe that now i explained well!
Sir 6v6gt i put your code inside but i noticed that when i push the button again after the first time it just reloads the delay while the ledUp1 stays on until the expire of time.
The first code you gave me it seems to work but with a lot of problems(once it works once it does not works)
if(millis() >= off1 || digitalRead(buttonUp) == LOW ) //see if it's time to turn off LED
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) )
{
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() < 4750 ) ) //see if it's time to turn off LED
{
digitalWrite(led1Up, LOW); //it's time. this also re-enables the button
}
//for the 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(millis() >= off2)
{
digitalWrite(led2Down, LOW);
}
}