Hi there,
Ive used the below script for years for a simple method of running a set relay at set intervals during the timer itself.
I normally use it for only a few minutes, eg, I would set the below to 180 for 3 minutes
uint8_t monoStandDevcountdown = 180
Everything would work fine, however when Ive went to set an hour, as 3600, it doesnt work, and instead comes up 16 seconds? Am I missing something plain obvious here? Ive been scratching my head for a while now and I bet the answer is something obvious. Maybe I'm looking too hard for a bigger issue.
void monoStandDevCycle() {
uint8_t monoStandDevcountdown = 3600;
uint8_t monoStandrelayCountdown = 15;
bool runningmonoStandDev = true;
bool updateDisplaymonoStandDev = true;
uint32_t countdownTimemonoStandDev = millis();
uint32_t relayOnTimemonoStandDev = 5;
uint32_t relayOffTimemonoStandDev = 25;
bool relayStatemonoStandDev = true;
//-enter the servo function below
agitationOn();
while (runningmonoStandDev) {
if (updateDisplaymonoStandDev) {
updateDisplaymonoStandDev = false;
lcd.setCursor(0, 2);
char m[3];
char s[3];
sprintf(m, "%02d", int(monoStandDevcountdown / 60));
sprintf(s, "%02d", monoStandDevcountdown % 60);
lcd.print(m);
lcd.print(":");
lcd.print(s);
//Below is the countdown in minutes and seconds for 7segment display
byte monoStandDevminutes = (monoStandDevcountdown / 60);
byte monoStandDevseconds = (monoStandDevcountdown % 60);
display1.printTime(monoStandDevminutes, monoStandDevseconds, true); // display time
if (relayStatemonoStandDev) {
lcd.print(" Agitating");
}
else {
lcd.print(" Standing");
}
lcd.setCursor(0, 4);
if (relayStatemonoStandDev) {
lcd.print("AGI stops in ");
}
else {
lcd.print("Next AGI in ");
}
sprintf(s, "%02d", monoStandrelayCountdown);
lcd.print(s);
}
// Every second: count down.
if (millis() - countdownTimemonoStandDev > 1000) {
if (monoStandDevcountdown == 0) { // Finished! (this happens after the last second has passed).
runningmonoStandDev = false;
}
monoStandDevcountdown--;
monoStandrelayCountdown--;
countdownTimemonoStandDev += 1000;
updateDisplaymonoStandDev = true;
if (monoStandrelayCountdown == 0) { // Switch the relay.
if (relayStatemonoStandDev) {
//enter the servo off function below
agitationOff();
relayStatemonoStandDev = false;
monoStandrelayCountdown = relayOffTimemonoStandDev;
}
else {
//enter the servo on function below
agitationOn();
relayStatemonoStandDev = true;
monoStandrelayCountdown = relayOnTimemonoStandDev;
}
}
}
}
lcd.clear();
display1.clear();
}
I appriciate the code is a bit of a mess but its worked well for years for me for a simple motor task. Just obviously not for such a long set time!