Hello, Thanks for checking my thread. I am having trouble with my code. I am writing a program for a: Recycling Timer for an aeroponics project. That turns on for a second then goes off for 1 hour, repeatedly.
The problem I have is that: it works for the first two “on” moments, at 1s when the program starts and at 1hr. But after that, the timing goes way off. by the time it’s hour 3, it turns on every 30 mins and ends up turning on at 15 mins interval by hour 4… it’s worse when I put in 30 min interval.
I tried so many thing like changing the ints to unsigned long, doesnt help. SO I came to the experts at the arduino forum!
Device: Seeduino v2.12, with Relay Shield from seeduino also.
Please lend me a helping hand. Here is my code:
/*
This Code will set a repeat cycle timer using the Metro Library.
*/
#include <Metro.h> //Include Metro library
unsigned char relayPin[4] = {4,5,6,7}; // Define the led's pin
extern volatile unsigned long timer0_overflow_count;
int mode[4]={LOW,LOW,LOW,LOW};
// Initiate a metro object and set the interval to 250 milliseconds (0.25 seconds).
Metro ledMetro1 = Metro(250);
Metro ledMetro2 = Metro(250);
Metro ledMetro3 = Metro(250);
Metro ledMetro4 = Metro(250);
unsigned long Sec = 1000;
unsigned long Min= 60*1000;
unsigned long onTime1=Sec;
unsigned long offTime1=60*Min;
void setup()
{
int i;
for(i = 0; i < 4; i++)
{
pinMode(relayPin[i],OUTPUT);
digitalWrite(relayPin[i],mode[i]);
}
}
void loop()
{
//Zone one
if (ledMetro1.check() == 1) { // check if the metro has passed its interval .
if (mode[0]==LOW) {
mode[0]=HIGH;
ledMetro1.interval(onTime1); // if the pin is HIGH, set the interval to onTime1.
}
else {
ledMetro1.interval(offTime1); // if the pin is LOW, set the interval to offTime1.
mode[0]=LOW;
}
digitalWrite(relayPin[0],mode[0]);
}
}
Moderator edit: CODE TAGS