I am writing a small program to control a Heat Revovery Ventillator(HRV). When the unit is plugged in or reset, I want the motor to go into Hi Speed mode for 2 minutes, then drop back to Low Speed and stays there until a bathroom timer is selected and it runs in High Speed. For the timers, I am using the millisDelay() function. It all works fine except for the initial or reset part of the program. I have attached the program, but I pasted the lines of code that are causing grief.
If you notice on setup() Iwant the motor to run on high speed( digitalWrite(ledMtrHiSpd, HIGH); // Relay K1 Energized). The next line shows the ledDelay.start(10000) a 10 secc. timer reduced from the 2 minutes which I will be using once all works fine. Jump down to the "void checkTurnOffLed" function and you see I use the ledDelay.just Finished to stop the motor from running on high speed and run it on low speed once the timer has stopped. The justFinished() only runs one time after the timer finishes. The justFinished() method MUST be called every loop() in order for the millisDelay to timeout. It only returns true just once after ledDelay.start is called.
If this is all the program I need, then it runs fine. However; when I include the code under the while(roomTimer == 1) section, when the timer is finished running,(it runs again at high speed then runs back down to low speed). It is when I include the two lines of code after the timer has ended where the problem comes into play.
digitalWrite(ledMtrLowSpd, HIGH);
digitalWrite(ledMtrHiSpd, LOW);
The problem is that on startup or reset, the motor runs at high speed for a fraction of a second until the arduino finishes its bootup, then turns off of high speed and runs the motor at low speed. The program ignores the ledDelay() timer.
I included the line ledDelay.remaining(); and you can watch it count down the remaing time of the ledDealy timer on the serial monitor.
My question is, How do I stop the program from jumping over the ledDelay() timer and let it do its thing by running the motor on high speed for 2 minutes(actual 10seconds) on startup or by reset , then down drop down to the Low speed it is designed to run.
Note: I use a lot of // throughout the program as I was trying different combos of code to see if I could make this thing to work. Definitely a work in progress.
Exerpts from the actual program:
millisDelay ledDelay;
void setup() {
//digitalWrite(ledDmprOpenClose, LOW); // Damper is Open Rely K3 De-energized
digitalWrite(ledMtrHiSpd, HIGH); // Relay K1 Energized
// digitalWrite(ledMtrLowSpd, LOW);
ledDelay.start(10000); //Start Delay 2 min. Motor on High Speed, Outside Dmpr Open
}
void checkTurnOffLed() { // the led task check if delay has timed out
if (ledDelay.justFinished()) { // Motor on Low Speed - Ouside Dmpr Open
// digitalWrite(ledDmprOpenClose, LOW);// Relay K3 Deenergized Damper is Open
digitalWrite(ledMtrHiSpd, LOW); // K2 Relay Deenergized
digitalWrite(ledMtrLowSpd, HIGH); //Relay K3 Energized
}
}
void loop() {
checkTurnOffLed(); // call the led task, may just return
Serial.println(ledDelay.remaining());
if (ledDelay.justFinished()) { // Motor on Low Speed - Ouside Dmpr Open
// digitalWrite(ledDmprOpenClose, LOW);// Relay K3 Deenergized Damper is Open
digitalWrite(ledMtrHiSpd, LOW); // K2 Relay Deenergized
digitalWrite(ledMtrLowSpd, HIGH); //Relay K3 Energized
}
ledDelay.remaining();
while (roomTimer ==1) // if the room timer is pressed
{
digitalWrite(ledMtrLowSpd, LOW); // turn fan low motor speed off
digitalWrite(ledMtrHiSpd, HIGH); // turn fan hi speed on
roomTimer = digitalRead(roomSw);
}
digitalWrite(ledMtrLowSpd, HIGH);
digitalWrite(ledMtrHiSpd, LOW);
Thank You
gameworm