I needed code to run a pump for 15 min every hour.
I tried using the Processor speed as a clock which worked after some help from the Forum...thanks again.
Somebody commented that Mills is not difficult when I said I also tried that rout. Well I like a challenge so here is my code.
The question I have. Is it possible that the program can miss a specific Mills. Sometimes when I run the program the printLn stating RESET LOOP TIMER is not in the monitor.
// constants won't change. Used here to set a pin number :
// Variables will change :
unsigned long previousMillis = 0; // will store last time cycle was reset
unsigned long LoopMillis;
int PumpRealayPin = 13;
// constants won't change :
const long LoopInterval = 3600000; // interval at which Cycle will reset
const long OnInterval = 150000; // interval at which Pump is on
void setup()
{
Serial.begin(9600);
pinMode (PumpRealayPin , OUTPUT);
digitalWrite (PumpRealayPin , HIGH);
}
void loop()
{
unsigned long RunningMillis = millis();
if (RunningMillis - previousMillis <= LoopInterval)
{
LoopMillis = (RunningMillis - previousMillis);
if (LoopMillis < OnInterval)
{
digitalWrite (PumpRealayPin , HIGH);
Serial.print(RunningMillis/1000);
Serial.println(" Pump is On");
}
else
{
digitalWrite(PumpRealayPin , LOW);
//Serial.print(RunningMillis/1000);
// Serial.println(" Pump is OFF");
}
}
else
{
previousMillis = RunningMillis;
Serial.println(" **** Reset Loop Timer ****** ");
}
}