Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Timer Lib or Timer interrupt for Teensy 3.0/3.1

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    9

    Timer Lib or Timer interrupt for Teensy 3.0/3.1

    Hi
    I am looking for Timer Lib or some Library with which I can schedule a timer. When the timer expires it will invoke the callback registered with it. Is there any such library ? if not, is there any ref code on Timer and Timer interrupt that I can look at ?
    This is for Teensy 3.1
    Thanks and regards,
    Vignesh

  2. #2
    Senior Member
    Join Date
    Mar 2013
    Location
    Austin TX
    Posts
    429
    This is what you need:
    IntervalTimer: http://pjrc.com/teensy/td_timing_IntervalTimer.html

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    9
    Thanks nox771 ! that worked !!
    I had tried the code mentioned in post #2 here :http://forum.pjrc.com/threads/25375-...ighlight=timer
    ..and it strangely did not work!
    here is my code in case if some one is interested..
    Thanks and Regards
    Vignesh

    IntervalTimer myTimer;
    const int ledPin = 13;
    int led_state = 0;

    void timer_fun()
    {
    if (led_state == 0)
    {
    digitalWrite(ledPin, HIGH); // set the LED on
    led_state = 1;
    }
    else
    {
    digitalWrite(ledPin, LOW); // set the LED off
    led_state = 0;
    }
    }

    void setup()
    {
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
    myTimer.begin(timer_fun, 150000);
    led_state = 0;
    }

    void loop()
    {
    Serial.println(led_state); // Not int protected !
    delay(500); // wait for a second
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •