alarm1.cpp

This sketch uses an alarm to print "I'm awake already" thirty seconds after it is powered up. The core software has support for 'alarms', which you can use to perform an event at some future time. When the alarm 'goes off', your function gets called, and it can do whatever it wants.

Alarms are created and accessed using the special Alarms object. Several alarms are used by the core software itself, but there's room for you to create at least a few dozen alarms as well, if you need that many!

This sketch shows the three basic steps to using an alarm:

  1. Write your 'alarm handler' function
  2. Create an alarm and pass it the name of your alarm handler. Each alarm has an associated 'alarm number', which you use to refer to it later.
  3. Use the alarm number to set the alarm.

// Alarm sketch 1: Print a message 30 seconds after power up

// Here's my alarm handler.  This kind of alarm handler (the simpler
// kind) must always be declared to take a one u32 argument, and to
// return void.
void myAlarmHandler(u32 when) {        
  println("I'm awake already");
}

void setup() {
  int num;
  num = Alarms.create(myAlarmHandler); // Create an alarm, get its number
  Alarms.set(num,30*1000);             // Set it for 30 seconds of uptime
}

void loop() { 
  /* Nothing to do */
}

Generated on Fri Apr 22 06:54:10 2011 for SFB by doxygen 1.5.9