-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHelloScheduler.ino
53 lines (45 loc) · 1.04 KB
/
HelloScheduler.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* HelloScheduler. Same as HelloCoroutine, but using the CoroutineScheduler.
*/
#include <Arduino.h>
#include <AceRoutine.h>
using namespace ace_routine;
#ifdef LED_BUILTIN
const int LED = LED_BUILTIN;
#else
// Some ESP32 boards do not define LED_BUILTIN. Sometimes they have more than
// 1. Replace this with the proper pin number.
const int LED = 5;
#endif
const int LED_ON = HIGH;
const int LED_OFF = LOW;
COROUTINE(blinkLed) {
COROUTINE_LOOP() {
digitalWrite(LED, LED_ON);
COROUTINE_DELAY(100);
digitalWrite(LED, LED_OFF);
COROUTINE_DELAY(500);
}
}
COROUTINE(printHelloWorld) {
COROUTINE_LOOP() {
Serial.print(F("Hello, "));
Serial.flush();
COROUTINE_DELAY(1000);
Serial.println(F("World"));
COROUTINE_DELAY(4000);
}
}
void setup() {
#if ! defined(EPOXY_DUINO)
delay(1000);
#endif
Serial.begin(115200);
while (!Serial); // Leonardo/Micro
pinMode(LED, OUTPUT);
// Auto-register all coroutines into the scheduler.
CoroutineScheduler::setup();
}
void loop() {
CoroutineScheduler::loop();
}