Difference between revisions of "OnTimer0"

From Pinguino
Jump to: navigation, search
m (1 revision)
(Documentation from paintitblack posted on the mailling list.)
Line 1: Line 1:
 
 
[[Category:LanguageReference]] [[Category:Functions]]
 
[[Category:LanguageReference]] [[Category:Functions]]
 
== Name ==
 
== Name ==
OnTimer0
+
OnTimer0 - Call a function at fixed interval
 
== Description ==
 
== Description ==
; Since Beta X
+
Call a function at a fixed interval using Timer0. The function is called indefinitely.
 +
; Since  
 +
beta 9.05
 
== Syntax ==
 
== Syntax ==
 +
  void OnTimer0(void (*callback)(), u8 timediv, u16 delay);
 +
 +
; callback
 +
Function called each time Timer0 trigger an interrupt
 +
 +
; timediv
 +
INT_MICROSEC, INT_MILLISEC or INT_SEC (for ms, us and sec.)
 +
 +
; delay
 +
time before interrupt is triggered (using timediv as unit)
 +
 
== Example ==
 
== Example ==
 +
 +
<source>
 +
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()
 +
{
 +
}
 +
</source>
 +
 
== Bugs ==
 
== Bugs ==
 +
 +
* No method documented to disable it.
 +
* Does multi-call to OnTime0() stacks? Or does the last one overwrite the previous one?
 +
 
== See also ==
 
== See also ==
 +
[[OnTimer1]]
 +
 +
[[OnTimer2]]
 
== Comments ==
 
== Comments ==

Revision as of 11:28, 31 August 2011

Name

OnTimer0 - Call a function at fixed interval

Description

Call a function at a fixed interval using Timer0. The function is called indefinitely.

Since

beta 9.05

Syntax

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

Function called each time Timer0 trigger an interrupt

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

  • No method documented to disable it.
  • Does multi-call to OnTime0() stacks? Or does the last one overwrite the previous one?

See also

OnTimer1

OnTimer2

Comments