I have recently discovered the chrono library and have been using for a project i am working on, however i am getting some unusal behaviour, which i am struggling to get to the bottom of, and i am hoping someone will be able to point out my error.
Specifically the problem is found when i stop and resume a chrono timer, and i have made a sketch to demonstrate what i am finding..
#include <Chrono.h>
boolean toggle1 = HIGH;
// Instantiate Chronos
Chrono chronoA;
Chrono chronoB;
Chrono chronoC;
Chrono chronoDisplay;
void setup() {
Serial.begin(57600);
while (!Serial) {
}
}
void loop() {
if (chronoA.hasPassed(5000)) { //Every 5 seconds..
toggle1 = !toggle1; //..toggle..
chronoA.restart(); //..and restart the chrono
}
if (toggle1 == LOW) { //If the toggle is low..
chronoB.stop(); //..pause the chrono
}
if (toggle1 == HIGH) { //If the toggle is High..
chronoB.resume(); //..resume the chrono
}
if (chronoDisplay.hasPassed(500)) { //Every 0.5seconds..
Serial.print("ChronoA: "); //..output the values to serial
Serial.println(chronoA.elapsed());
Serial.print("ChronoB: ");
Serial.println(chronoB.elapsed());
Serial.print("ChronoC: ");
Serial.println(chronoC.elapsed());
Serial.print("Toggle Position: ");
Serial.println(toggle1);
Serial.print("Is chronoB Running: ");
Serial.println(chronoB.isRunning());
chronoDisplay.restart();
}
}
The sketch is intended to stop and resume chonoB every 5 seconds, so for 5 seconds it would count up, then stop for 5 seconds, and then count up for a additional 5 seconds etc etc.
However i am finding that chronoB does count up but does not follow any kind of pattern.
If someone could point out my error i would be very grateful!
PaulS:
If we could see the output, perhaps the pattern would be obvious to someone, who could then suggest what the problem is, and maybe even a solution.
Heh.
@OP (who is devil plus one, I guess ...)
Move the curly brace from right under the line:
</sub> <sub> chronoA.restart(); //..and restart the chrono</sub> <sub>
to the end of your sketch, and it works, right?
I don't see the point though. Chrono.reset() is cool, but it just seems like an extraneous level of abstraction on top of an already abstracted construct, namely millis() counting.