Statistics
| Revision:

root / Ports / examples / schedule / schedule.pde

History | View | Annotate | Download (1.3 KB)

1
//>>> The latest version of this code can be found at https://github.com/jcw/ !!
2
3
// Demo sketch demonstrating the Scheduler class
4
// 2010-10-18 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php
5
// $Id: schedule.pde 7763 2011-12-11 01:28:16Z jcw $
6
7
#include <Ports.h>
8
#include <RF12.h>
9
10
enum { TASK1, TASK2, TASK_LIMIT };
11
12
static word schedBuf[TASK_LIMIT];
13
Scheduler scheduler (schedBuf, TASK_LIMIT);
14
15
BlinkPlug leds (3);
16
byte led1, led2;
17
18
// this has to be added since we're using the watchdog for low-power waiting
19
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
20
21
void setup () {
22
    Serial.begin(57600);
23
    Serial.println("\n[schedule]");
24
    
25
    // turn the radio off completely
26
    rf12_initialize(17, RF12_868MHZ);
27
    rf12_sleep(RF12_SLEEP);
28
29
    leds.ledOff(1+2);
30
    
31
    // start both tasks 1.5 seconds from now
32
    scheduler.timer(TASK1, 15);
33
    scheduler.timer(TASK2, 15);
34
}
35
36
void loop () {
37
    switch (scheduler.pollWaiting()) {
38
        // LED 1 blinks regularly, once a second
39
        case TASK1:
40
            led1 = !led1;
41
            if (led1) leds.ledOn(1); else leds.ledOff(1);
42
            scheduler.timer(TASK1, 5);
43
            break;
44
        // LED 2 blinks with short on pulses and slightly slower
45
        case TASK2:
46
            led2 = !led2;
47
            if (led2) leds.ledOn(2); else leds.ledOff(2);
48
            scheduler.timer(TASK2, 11 - 10 * led2);
49
            break;
50
    }
51
}