-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHelloManualCoroutine.ino
61 lines (53 loc) · 1.33 KB
/
HelloManualCoroutine.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
54
55
56
57
58
59
60
61
/*
* HelloManualCoroutine. Same as HelloCoroutine but using explicit Coroutine
* subclasses and manually creating the coroutine instances.
*/
#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
// one built-in LEDs. Replace this with the pin number of your LED.
const int LED = 5;
#endif
const int LED_ON = HIGH;
const int LED_OFF = LOW;
class BlinkLedCoroutine: public Coroutine {
public:
int runCoroutine() override {
COROUTINE_LOOP() {
digitalWrite(LED, LED_ON);
COROUTINE_DELAY(100);
digitalWrite(LED, LED_OFF);
COROUTINE_DELAY(500);
}
}
};
class PrintHelloWorldCoroutine: public Coroutine {
public:
int runCoroutine() override {
COROUTINE_LOOP() {
Serial.print(F("Hello, "));
Serial.flush();
COROUTINE_DELAY(1000);
Serial.println(F("World"));
COROUTINE_DELAY(4000);
}
}
};
BlinkLedCoroutine blinkLed;
PrintHelloWorldCoroutine printHelloWorld;
void setup() {
#if ! defined(EPOXY_DUINO)
delay(1000);
#endif
Serial.begin(115200);
while (!Serial); // Leonardo/Micro
pinMode(LED, OUTPUT);
}
void loop() {
blinkLed.runCoroutine();
printHelloWorld.runCoroutine();
}