-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHelloSchedulerWithProfiler.ino
113 lines (94 loc) · 2.87 KB
/
HelloSchedulerWithProfiler.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
HelloSchedulerWithProfiler, a demo of the LogBinProfiler. The CoroutineScheduler
will automatically use the Profiler if it is defined on the Coroutine.
Every 5 seconds, the following will be printed on the Serial monitor.
**SparkFun Pro Micro**
* flash/ram = 7454/271
```
name <16us <32us <64us<128us<256us<512us <1ms <2ms <4ms <8ms >>
0x1DB 16898 52688 0 0 0 0 0 0 0 0 1
readPin 65535 1128 0 0 0 0 0 0 0 0 0
blinkLed 65535 800 0 0 0 0 0 0 0 0 0
{
"0x1DB":[16898,52688,0,0,0,0,0,0,0,0,1],
"readPin":[65535,1128,0,0,0,0,0,0,0,0,0],
"blinkLed":[65535,800,0,0,0,0,0,0,0,0,0]
}
```
**ESP8266**
```
name <8us <16us <32us <64us<128us<256us<512us <1ms <2ms <4ms >>
0x3FFEE4D0 65535 37 2 0 0 0 0 0 0 0 1
readPin 65535 274 0 0 0 0 0 0 0 0 0
blinkLed 65535 47 0 0 0 0 0 0 0 0 0
{
"0x3FFEE4D0":[65535,37,2,0,0,0,0,0,0,0,1],
"readPin":[65535,274,0,0,0,0,0,0,0,0,0],
"blinkLed":[65535,47,0,0,0,0,0,0,0,0,0]
}
```
*/
#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 PIN = 2;
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(readPin) {
COROUTINE_LOOP() {
(void) digitalRead(PIN);
COROUTINE_DELAY(20);
}
}
// A coroutine that prints the profiling information every 5 seconds. It will
// include information about itself.
COROUTINE(printProfiling) {
COROUTINE_LOOP() {
#if defined(ARDUINO_ARCH_AVR)
LogBinTableRenderer::printTo(
Serial, 3 /*startBin*/, 14 /*endBin*/, false /*clear*/);
LogBinJsonRenderer::printTo(
Serial, 3 /*startBin*/, 14 /*endBin*/);
#else
LogBinTableRenderer::printTo(
Serial, 2 /*startBin*/, 13 /*endBin*/, false /*clear*/);
LogBinJsonRenderer::printTo(
Serial, 2 /*startBin*/, 13 /*endBin*/);
#endif
COROUTINE_DELAY(5000);
}
}
void setup() {
#if ! defined(EPOXY_DUINO)
delay(1000);
#endif
Serial.begin(115200);
while (!Serial); // Leonardo/Micro
pinMode(LED, OUTPUT);
pinMode(PIN, INPUT);
// Coroutine names can be either C-string or F-string.
blinkLed.setName("blinkLed");
readPin.setName(F("readPin"));
// Create a profiler on the heap for every coroutine.
LogBinProfiler::createProfilers();
// Setup the scheduler.
CoroutineScheduler::setup();
}
void loop() {
CoroutineScheduler::loopWithProfiler();
}