Dear all,
I am currently doing a small project involving a push button, relay board, buzzer, arduinomega
Basically after 40minutes a buzzer is switched ON.
If the user does not press the button in 5minutes the arduino gives a short (relay).
My code is very basic (since I have not touched in a long time).
Can you please help regarding the overflow. After 49 days the timer misbehaves and goes haywire.
I have tried doing the 'hack' but the timer goes crazy.
Below is the code:
const byte button=6;
const byte buttonreset=5; //da definire
const int outputIndicator=2;
const int outputBuzzer=3;
const int outputPanel=4;
int interval = 1000; //to find what value i have to give
extern volatile unsigned long timer0_millis; //timer hack
int buttonState=0;
int buttonresetState=0; //da definire
unsigned long timer1;
//unsigned long currentMillis = millis();
unsigned long previousMillis=0;
void setup() {
pinMode(button, INPUT); //reset
pinMode(buttonreset, INPUT); //da definire
pinMode(outputIndicator, OUTPUT);
pinMode(outputBuzzer, OUTPUT);
pinMode(outputPanel, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Serial.print(timer1);
buttonState = digitalRead (button);
buttonresetState = digitalRead (buttonreset);//da definire
if (buttonState == HIGH )
{
digitalWrite (outputIndicator, HIGH);
timer1=millis();
digitalWrite (outputBuzzer, LOW);
digitalWrite (outputPanel, LOW);
noInterrupts (); //hack to reset timer
timer0_millis = 0;
interrupts ();
}
else
{
digitalWrite (outputIndicator, LOW);
if (millis()-timer1>2400000 ) //40min
{
digitalWrite (outputBuzzer, HIGH);
// delay(3000);
}
else if (millis()-timer1>2430000 ) //42min
{
digitalWrite (outputPanel, HIGH);
// delay(500);
}
}
//}
}