I'm using SimpleTimer for a 1 minute timer to update a clock and a 5 minute timer to take sensor readings. The 1 minute timer works perfectly, but the longer timer never fires. If I shorten it to 90 seconds, it works. Given that the call uses a long, why is 180000 or 300000 (5 minutes) a problem? I even tried declaring a long variable and using it, but it still didn't work for the "longer" interval.
#include <SimpleTimer.h>
SimpleTimer timer;
void setup() {
Serial.begin(57600);
timer.setInterval(60000, OneMinute);
timer.setInterval(180000, ThreeMinutes);
void loop() {
timer.run();
void OneMinute() {
Serial.println("1 minute timer");
void ThreeMinutes() {
Serial.println("3 minute timer");
By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with:
a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u
a 'l' or 'L' to force the constant into a long data format. Example: 100000L
a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul
https://www.arduino.cc/reference/en/language/variables/constants/integerconstants/
Interesting. From the SimpleTimer.h file, it shows the call accepting a long.
// call function f every d milliseconds
int setInterval(long d, timer_callback f);
I tried 180000UL and it didn't work.
This is what I see in the monitor
12:12:32.986 -> 1 minute timer
12:13:33.227 -> 1 minute timer
12:14:33.524 -> 1 minute timer
12:14:33.524 -> 3 minute timer
12:15:33.807 -> 1 minute timer
12:16:34.082 -> 1 minute timer
12:17:34.335 -> 1 minute timer
12:17:34.335 -> 3 minute timer
180000 is well within limits of long and unsigned long. Hence I do not understand the different behaviour.
And indeed unsigned would make more sense (as negative intervals make no sense).
OP did not tell what board he uses.
There is an updated version of this M.Romani library on GitHub
https://github.com/marcelloromani/Arduino-SimpleTimer
It indeed uses the unsigned long
// call function f every d milliseconds
int setInterval(unsigned long d, timer_callback f);
The code through the Playground uses long
// call function f every d milliseconds
int setInterval(long d, timer_callback f);
Yes, that appears to be the latest release (v2.0) of that library.
Where do you find the library with files dated 5/29/2017?
Does it have the function with an unsigned long?
I've had it on my computer for years, so I don't know when I installed it.
I tried
unsigned long time3min;
and passing time3min, but it didn't work.
ScottMurchison:
I've had it on my computer for years, so I don't know when I installed it.
I would delete it, and install the zip library from github. It is functioning as you want.