Hi,
I have 2Chanell-Relay and 3 buttons, I manage to make this... When I press btn1 chanell1 is ON with timer like 10min. When the timer is done (after 10min) the Chanell2 is OFF...
Same with button2, when I press btn2, chanell2 is ON with timer of 10min, When the timer is done (after 10min) the Chanell2 is OFF
I want to make btn3 to be like when I press it during those 10min. channel1 and chanel2 to be OFF, as well as the timer...
Untill now I manege to do this: wen I press button3 Chanels are OFF but until the timer is done (I'm waiting for 10min) I cant start ON any chanels....I have to wait 10 minits so I can turn any Chanel ON
I need thiis btn3 to turn OFF the timmer as well so I can turn ON chanels again whithout waiting
Here is my Code:
const int button1 = 8; // the number of the pushbutton pin
const int button2 = 9;
const int button3 = 10;
const int CHANEL1 = 2; //Chanels of the Relay
const int CHANEL2 = 3;
unsigned long off_time;
boolean CHANEL1State=false;
boolean CHANEL2State=false;
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status
int button3State = 0;
void setup() {
// initialize the CHANEL pin as an output:
pinMode(CHANEL1, OUTPUT);
pinMode(CHANEL2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1, INPUT);
pinMode(button2, INPUT);
//// initialize the state of the relay chanels (OFF):
digitalWrite(CHANEL1, HIGH);
digitalWrite(CHANEL2, HIGH);
resetChanells();
}
void loop(){
button3State = digitalRead(button3);
///////////// CHANEL1 BUTTON 1 ////////
if ((CHANEL1State) && (millis()>=off_time)) /* is it on and is it later or equal to off_time /
{
digitalWrite(CHANEL1,HIGH);
CHANEL1State = false;
}
else if (!CHANEL1State) / is it off? /
{
button1State = digitalRead(button1);
if(button1State == HIGH)
{
digitalWrite(CHANEL1, LOW);
CHANEL1State = true;
off_time = millis() + 5000;
}
}
///////////// CHANEL2 BUTTON 2 ////////
if ((CHANEL2State) && (millis()>=off_time)) / is it on and is it later or equal to off_time /
{
digitalWrite(CHANEL2,HIGH);
CHANEL2State = false;
}
else if (!CHANEL2State) / is it off? */
{
button2State = digitalRead(button2);
if(button2State == HIGH)
{
digitalWrite(CHANEL2, LOW);
CHANEL2State = true;
off_time = millis() + 5000;
}
}
///////////////////// BUTTON 3 TURN OFF CHANELS //////
if (button3State == HIGH) {
resetChanells();
}
}
void resetChanells()
{
digitalWrite(CHANEL1, HIGH);
digitalWrite(CHANEL2, HIGH);
}