Can I use CurieTimerOne lib inside of another library?

Hello! I was just made aware of the Arduino101 section of the forum. I have posted a question regarding the use of the CurieTimerOne library from within another library. I am having issues with my ISR not working properly once I have moved my code from a sketch to the library format (.cpp, .h and example .ino). Can anyone point me in the right direction?

Thanks in advance!

http://forum.arduino.cc/index.php?topic=446520.0

Hi, it looks like you made a few changes in the other thread.. could you post the most up-to-date code, here, please?

Morning!

I have a very simplified version of what I want to do in hopes of pinpointing what the error is. Instead of the LED being toggled every time the ISR is called, it turns on and remains on. It seems like there is an issue with calling CurieTimerOne.start() from the library, but not from the IDE. The toggleLed() function is in there just as a sanity check to make sure the library was working, but is not being called.

.h

#ifndef testLib_Timer1_h
#define testLib_Timer1_h

#include <CurieTimerOne.h>

class testLib_Timer1
{
public:
    void Initialize();
    void toggleLed();
    
protected:
    
};


#endif /* testLib_Timer1_h */

.cpp

#include "testLib_Timer1.h"


const int oneSecInUsec = 1000000;   // A second in mirco second unit.
volatile bool toggle = 0;

void timedBlinkISR()
{
    digitalWrite(13,toggle);
    toggle = !toggle;
}

void testLib_Timer1::Initialize()
{
    pinMode(13, OUTPUT);
    CurieTimerOne.start(2000, timedBlinkISR);
}

void testLib_Timer1::toggleLed()
{
    if(toggle == 0)
    {
        digitalWrite(13,HIGH);
        toggle = 1;
    }
    else
    {
        digitalWrite(13, LOW);
        toggle = 0;
    }
}

.ino

#include <testLib_Timer1.h>

testLib_Timer1 myTest;

void setup() {
  // put your setup code here, to run once:
  myTest.Initialize();

}

void loop() {
  // put your main code here, to run repeatedly:
  //myTest.toggleLed();
  //delay(2000);
  //myTest.toggleLed();
  //delay(2000);

}

Decreasing the ISR interval ended up solving my issue with the LED. I just wasn't giving it enough time to turn on and off.

Ah, of course, parameter is microsec not ms. Good catch.