forked from bxparks/AceRoutine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoundManager.ino
65 lines (59 loc) · 1.63 KB
/
SoundManager.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
/*
* An example of using the Coroutine::reset() from one coroutine to control the
* state of another coroutine. The SoundRoutine plays different sounds
* depending on the 'currentSound' variable. The soundManager coroutine is able
* to interrupt and reset the SoundRoutine to play a different sound.
*
* Adapted from the example posted by EkardNT@ on
* https://github.com/bxparks/AceRoutine/issues/20.
*
* This example also demonstrates how coroutines can be defined in separate
* *.cpp and *.h files. See https://github.com/bxparks/AceRoutine/issues/39.
*
* The output of this program should be the following:
*
* @verbatim
* <silence>
* Wait 5 seconds...
*
* Request Beep and wait 5 seconds...
* Coroutine soundRoutine; status: Yielding
* Coroutine soundManager; status: Running
* First BEEP
* Second BEEP
*
* Request Boop and wait 5 seconds...
* Coroutine soundRoutine; status: Yielding
* Coroutine soundManager; status: Running
* First BOOP
* Second BOOP
*
* Request Silence and wait 5 seconds...
* Coroutine soundRoutine; status: Yielding
* Coroutine soundManager; status: Running
* Wait 5 seconds...
* <silence>
*
* Request Beep and wait 5 seconds...
* Coroutine soundRoutine; status: Yielding
* Coroutine soundManager; status: Running
* First BEEP
* Second BEEP
*
* ...
* @endverbatim
*/
#include <Arduino.h>
#include <AceRoutine.h>
#include "SoundRoutine.h"
using ace_routine::CoroutineScheduler;
SoundRoutine soundRoutine;
void setup() {
delay(1000);
Serial.begin(115200);
while (!Serial); // needed for Leonardo/Micro
CoroutineScheduler::setup();
}
void loop() {
CoroutineScheduler::loop();
}