Problem with MsTimer2 on mega 2560

For some reason I can’t get the MsTimer2 library to work correctly on my mega 2560.

Here’s the code:

#include <MsTimer2.h>

// Switch on LED on pin 13 each second


void flash() {
  static boolean output = HIGH;
  
  digitalWrite(13, output);
  output = !output;
}

void setup() {
  pinMode(13, OUTPUT);

  MsTimer2::set(500, flash); // 500ms period
  MsTimer2::start();
}

void loop() {
}

It compiles but after I upload the sketch the LED blinks two times then stops. I tried using MsTimer2 in a couple other sketches with the same result; compiles OK but does not function.
I’m stumped at the moment. I’m not sure if the library is corrupted or if it’s a hardware incompatability issue.

As always thanks for any replies,
DigitalJohnson

There was no mega 2560 board when MsTimer2 was released, so it doesn't handle 2560 chip correctly. There is a patch file showing the changes (note the - and + lines) needed for it to work with the 2560 chip.

In the latest release the file name in the library is named MsTimer2.cpp.patch. With that info you can manually edit the MsTimer2.cpp file with the changes and try that.

Lefty

Thanks RL DJ