i was trying to turn on two relays one by one for a specific time using a button...and i did that.. but now i want to add a timer function for 5,10 and 20 minutes and i want to change this interval using a button like if i press the button no. 2 for 1 time the process will run for 5 minutes and 10 minutes for 2nd time and 20 minutes for the third time.... i added the button checking program as interrupt but the thing is arduino is not acceoting no. more than 200000 doesnt matter if i use "long/unsigned long"...please help
#include <TimerOne.h>
int in1 = 10;//relay 1
int nbc, nbc1; //to jumpout the loop
int in2 = 11;//relay 2
int led = 13;
int but1 = 8;
uint32_t interval;
int val;
int extra;
int but = 12;//button state
int bc = 0;//button counter
int lbs = 0;//last button stage
int bs = 0;//button state
int bc1 = 0;//button1 counter
int lbs1 = 0;//last button1 stage
int bs1 = 0; //button1 state
// relay 1 on
void forward()
{ Serial.print("clk");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
}
//both relay stop
void stp()
{
Serial.print("stp");
if (nbc != bc || nbc1 != bc1 ) //to check if the button is pressed in the middle
{
loop();//go back to loop
}
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
//2nd relay on
void reverse()
{ Serial.print("anticlk");
digitalWrite(in1, LOW); digitalWrite(in2, HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(in1, OUTPUT);//relay 1 o/p
pinMode(in2, OUTPUT);//relay2 o/p
pinMode(but, INPUT);//but input
Timer1.initialize(200000);//timer
Timer1.attachInterrupt(chkbtn);//timer to execute funtion
pinMode(led, OUTPUT);//normal process
}
void chkbtn()//to check if the button is pressed
{
bs = digitalRead(but);
bs1 = digitalRead(but1);
if (bs != lbs || bs1 != lbs1) {
if (bs == HIGH)
{
bc = bc + 1;//changing bc value
}
//2nd button condition for time interval
if (bs1 == HIGH)
{
bc1 = bc1 + 1;
if (bc1 = 1)
{
nbc1 = 1;
interval = 300000;
}
if (bc1 = 2)
{ nbc1 = 2;
interval = 600000;
}
if (bc1 = 3)
{ nbc1 = 3;
interval = 12000000;
}
}
}
}
void loop() {
digitalWrite(led, HIGH);
delay(300);
digitalWrite(led, LOW);
delay(200);
//loop to run the process for till interval
for (uint32_t timee = millis(); (millis() - timee) < interval;) {
if (bc == 1)
{
Serial.print(interval);
nbc = 1;
//2nd button state
Serial.print("light");
forward();
delay(5000);
stp();
delay(3000);
reverse();
delay(5000);
stp();
delay(3000);
}
if (bc == 2)
{ nbc = 2;
Serial.print("mid");
forward();
delay(10000);
stp();
delay(3000);
reverse();
delay(10000);
stp();
delay(3000);
}
if (bc == 3)
{ nbc = 3;
Serial.print("heavy");
forward();
delay(30000);
stp();
delay(3000);
reverse();
delay(30000);
stp();
delay(3000);
}
if (bc > 3)
{
bc = 0;
}
}
Serial.print(bc);
}