Simple SimpleTimer problem

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");  
}

Try
180000UL

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/

Does the timer.begin() take a long?

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.

You should make 2 timers..

SimpleTimer timer1;
SimpleTimer timer2;

Each timer can only handle one interval....

Tried 2 timers to no avail. There is a widely available demo sketch that shows one timer with four events.

OK.
I cannot help you then. Sorry...

When I change this line to

 timer.setInterval(180000l, ThreeMinutes);

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

That's great!
I do not see how 180000UL would differ from 180000L...

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);

CattleDog, that updated library failed to install

"Error: 13 INTERNAL: Library install failed: moving extracted archive to destination dir: library not valid"

Did you download the zip library and then use the library manager to install that?

Yes.

The header and cpp files are dated 3/28/2017. The library I'm using has files dated 5/29/2017, so the library update you pointed to is older.

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.

I would delete it, and install the zip library from github. It is functioning as you want.

I agree Delta_G