parameter does not work for metro (1 * 60 * 1000) ... metro (1.0 * 60 * 1000) works fine
please try the following code:
Metro metroHeartbeat = Metro(1000);
Metro metroWithDotDefine = Metro(METROWITHDOT * 60 * 1000); // works Metro metroWithOutDotDefine = Metro(METROWITHOUTDOT * 60 * 1000); // does not work Metro metroWithDot = Metro(1.0 * 60 * 1000); // works Metro metroWithOutDot = Metro(1 * 60 * 1000); // does not work Metro metro1MinuteWithDot = Metro (60000.0); // works Metro metro1MinuteWithOutDot = Metro (60000); // works
int counter = 1;
void setup()
{
Serial.begin(9600);
}
void loop() { if (metroHeartbeat.check() == 1) { Serial.print("Heartbeat: "); Serial.println(counter, DEC); counter++; }
if (metroWithDotDefine.check() == 1)
{
Serial.println("MetroWithDotDefine_____triggered");
}
if (metroWithOutDotDefine.check() == 1)
{
Serial.println("METROWITHOUTDOTDEFINE_TRIGGERED");
}
if (metroWithDot.check() == 1)
{
Serial.println("MetroWithDot___________triggered");
}
if (metroWithOutDot.check() == 1)
{
Serial.println("METROWITHOUTDOT________TRIGGERED");
}
if (metro1MinuteWithDot.check() == 1)
{
Serial.println("Metro1MinuteWithDot____triggered");
}
if (metro1MinuteWithOutDot.check() == 1)
{
Serial.println("Metro1MinuteWithOutDot_triggered");
}
}
i never see any serial printout in capital letters ;(
can you confirm?
Henning
Hello Henning, that is not a problem of the library. 1601000 is calculated as a standard int for the arduino compiler. This means that it is calculated with a 16 bit signed integer. Such a integer is limited to 32767. Whenever using bigger numbers append a L to the number to inform the compiler it is a long integer. This way the whole calculation will be done with the largest integer present. You can see this effect with the following sketch:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(60*1000); // prints out -5536
Serial.println(60L*1000); // prints out 60000
delay(2000);
}
At the end you are giving the wrong parameter to the constructor. With the dot you calculate in float which also provides a right result.