So here is the final code, all timers work the way they should on the breadboard. I used shorter interval timers just to test functionality over the past twelve hours or so and have been periodically checking the particle console to monitor the time stamps and ensure there has not been any dwell. Any suggestions or improvements that you would recommend? Anything that I may have over looked?
Thanks.
const int btn = D0; // Button is connected to D0
const int glp = D2; // GLP system connected to D2
const int wpm = D4; // WPM system connected to D4
const int fan = D6; // FAN system connected to D6
const int btnIndicate = D7; // LED is connected to D1
int state; // variable to store the state of btn
int counterWpm = 0; // variable to store WPM counter
long startTime = 0; // variable to store time of intial button press
bool btnState = false; // variable to store the state of the button
Timer offWpm (60000, wpmFunction, true); // sets period that the WPM system is active
Timer onWpm (60000, wpmOn, true); // sets period that the WPM system is inactive
Timer offGlp (90000, glpOff, true); // sets period that the GLP system is active
Timer onGlp (120000, glpOn, true); // sets period that the GLP system is inactive
Timer offFan (60000, fanOff, true); //sets period that the FAN system is active
Timer onFan (120000, fanOn, true); // sets period that the FAN system is inactive
Timer delayFan (180000, fanOn, true); // sets period that the FAN system waits before starting intial cycle
void setup()
{
pinMode(wpm, OUTPUT); // control pin for WPM system
pinMode(glp,OUTPUT); // control pin for GLP system
pinMode(fan, OUTPUT); // control pin for FAN system
pinMode(btnIndicate, OUTPUT); // sets D7 led as indicator
pinMode(btn, INPUT_PULLDOWN); // sets pin as input for btn
Particle.publish("SYSTEM STARTED", PRIVATE);
}
void loop()
{
btnState = digitalRead(btn); // read the state of btn
if ((btnState == true) && (state != 0)) {
delay(50); // protect against bounce
digitalWrite(btnIndicate, btnState); // turns D7 led on for visual confirmation
startTime = Time.now(); // sets startTime to time of intial button press
intializeTimers(); // start all system timers
Particle.publish("BUTTON PRESSED", PRIVATE);
state = 0; // sets state
return; // if statement is true, ignore rest of function
}
if ((btnState == false) && (state != 1)) {
delay(50); // protect against bounce
Particle.publish("WAITING", PRIVATE);
state = 1; // sets state
return; // if statement is true, ignore rest of function
}
}
void intializeTimers()
{
digitalWrite(wpm, HIGH); // begins WPM ON cycle
offWpm.start(); // intialize timer
Particle.publish("WPM ON: Cycle will end in 1 minute.", PRIVATE);
digitalWrite(glp, HIGH); // begins intial GLP ON cycle
offGlp.start(); // intialize timer
Particle.publish("GLP ON: Cycle will end in 1.5 minutes.", PRIVATE);
digitalWrite(fan, LOW); // begins FAN delay period
delayFan.start(); // intialize timer
Particle.publish("FAN: Cycle will begin in 3 minutes.", PRIVATE);
}
void wpmOn()
{
digitalWrite(wpm, HIGH); // turns WPM system on
offWpm.start(); // intialize time
Particle.publish("WPM ON: Cycle begin.", PRIVATE);
}
void wpmFunction()
{
if (counterWpm == 0) {
counterWpm++; // increments counterWpm by 1
digitalWrite(wpm, LOW); // turns WPM system off
onWpm.changePeriod(120000); // changes period until WPM sytem turns on
onWpm.reset(); // resets timer onWpm
Particle.publish("WPM OFF: Cycle (1) will begin in 2 minutes.", PRIVATE);
return; // if statement is true, ignore the rest of the function
}
if (counterWpm == 1) {
counterWpm++; // increments counterWpm by 1
digitalWrite(wpm, LOW); // turns WPM system off
onWpm.changePeriod(120000); // changes period until WPM sytem turns on
onWpm.reset(); // resets timer onWpm
Particle.publish("WPM OFF: Cycle (2) will begin in 2 minutes.", PRIVATE);
return; // if statement is true, ignore the rest of the function
}
if (counterWpm == 2) {
digitalWrite(wpm, LOW); // turns WPM system off
onWpm.changePeriod(240000); // changes period until WPM sytem turns on
onWpm.reset(); // rests timer onWpm
Particle.publish("WPM OFF: Cycle will begin in 4 minutes.", String(startTime), PRIVATE);
return; // if statement is true, ignore the rest of the function
}
}
void glpOn()
{
digitalWrite(glp, HIGH); // turns GLP system on
offGlp.start(); // intialize timer
Particle.publish("GLP ON: Cycle will end in 2 minutes.", PRIVATE);
}
void glpOff()
{
digitalWrite(glp, LOW); // turns GLP system off
onGlp.start(); // intialize timer onGLP
Particle.publish("GLP OFF: Cycle will begin in 1.5 minutes.", PRIVATE);
}
void fanOn()
{
digitalWrite(fan, HIGH); // turns FAN system on
offFan.start(); // intialize timer
Particle.publish("FAN ON: Cycle will end in 1 minute.", PRIVATE);
}
void fanOff()
{
digitalWrite(fan, LOW); // turns FAN system off
onFan.start(); // intialize timer
Particle.publish("FAN OFF: Cycle will begin in 2 minutes.", PRIVATE);
}
//END