timer3.cpp

This sketch uses split times to perform operations at different times within a single lap. It blinks the red and green leds once per second, for different and partially overlapping intervals.

In addition to the lap time handler, each timer can also have up to three 'split time handlers'. Split times are identified by their index number -- either 1, 2, or 3. Each split time can happen on any tick within the lap, and a different (or the same, or no) handler can be called for each split.

// Hardware Timer sketch 3: Using split timers

void onRed() {    ledOn(BODY_RGB_RED_PIN); }       
void onGreen() {  ledOn(BODY_RGB_GREEN_PIN); }       
void offRed() {   ledOff(BODY_RGB_RED_PIN); }       
void offGreen() { ledOff(BODY_RGB_GREEN_PIN); }       

void setup() {
  Timer1.begin();               // 1KHz tick, 1Hz lap 
  Timer1.setSplitHandler(3,100,onRed);   // Split 3: At 100ms, turn on red
  Timer1.setSplitHandler(1,600,offRed);  // Split 1: At 600ms, turn off red
  Timer1.setSplitHandler(2,400,onGreen); // Split 2: At 400ms, turn on green
  Timer1.setLapHandler(offGreen);        // At the lap, turn off green
  Timer1.start();               // And start the timer
}

void loop() { }


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