src:
http://forum.arduino.cc/index.php/topic,44030.0.html
http://playground.arduino.cc/Main/MsTimer2
notes:
------------
// Uptime counter
#include <MsTimer2.h>
volatile unsigned long _Uptime =0;
void updateuptime() {
_Uptime++;
}
unsigned long getUpTime()
{
unsigned long ret;
// optional: disable interrupts
cli();
ret = _Uptime;
// optional: enable interrupts
sei();
return ret;
}
void setup() {
MsTimer2::set(1000, updateuptime);
MsTimer2::start();
}
void loop() {
// call getUpTime here.
}
沒有留言:
張貼留言