OnTimer0

From Pinguino
Jump to: navigation, search

Name

OnTimer0 - Call a function at fixed interval

Description

This function is only available for 8-bit Pinguinos as 32-bit don't have any Timer 0.

Call a function at a fixed interval using Timer 0.

The function is called indefinitely until Int.detach() is called.

If Timer 0 is free, OnTimer0() will return the number of the interrupt, otherwise it will return "false".

Multi-call to OnTimer0() is not allowed. Function will then return "false" and produce "Error : interrupt TIMER0 is already used !" on the debug output.

If overwrite is needed, always use Int.detach() with the interrupt number before new declaration.

Since

beta 9.05

Syntax

 void OnTimer0(void (*callback)(), u8 timediv, u16 delay);
callback

Function called each time Timer0 trigger an interrupt. No argument is allowed in this function.

timediv

INT_MICROSEC, INT_MILLISEC or INT_SEC (for ms, us and sec.)

delay

time before interrupt is triggered (using timediv as unit)

Example

void blink13()
{
	toggle(13); // set pin 13 high if it's low and vice-versa
}

void setup()
{
       pinMode(13, OUTPUT);
       OnTimer0(blink13, INT_MILLISEC, 500); // Use Timer0 to toggle pin 13 every 500 ms
}

void loop()
{
}

Bugs

See also

OnTimer1 OnTimer2 OnTimer3 OnTimer4

OnTimer5 OnTimer6 OnTimer8 Int.detach

Comments

OnTimer0 works on all 8-bit boards, 32-bit boards don't have any Timer 0.