-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgong_03_exti2s.ino
More file actions
172 lines (142 loc) · 4.92 KB
/
Copy pathgong_03_exti2s.ino
File metadata and controls
172 lines (142 loc) · 4.92 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
gong-exti2s - Achtsamkeit-Glocke
Jens, 2021-02-24
sound files based on samples from
freesound https://freesound.org/
with appropriate licenses
board: ESP32 pico kit
note:
'partition scheme: no OTA' --> 1.3 Mbyte wav files in PROGMEM
MIT License
*/
//#include <WiFi.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"
#include "bell.h"
#include "bowl.h"
#include "clock.h"
#include "dingdong.h"
#include "feedback.h"
#include "gong.h"
#include "horn.h"
#include "laser.h"
#include "over.h"
#include "power.h"
#include "tin.h"
AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;
// non-blocking timer
unsigned long previousMillis = 0;
const unsigned long interval = 60000; // 1 min
const int wait = 60; // 60 min
int count = 0;
void show_help() {
const char helpstr[] = "\
\nGong - Achtsamkeits-Glocke\n\
bBcdfghlpto - sounds\n\
0 - sound off\n\
1..9 - volume\n\
s - speed up timer\n\
? - help\n";
Serial.println(helpstr);
}
void setup() {
// WiFi.mode(WIFI_OFF);
Serial.begin(115200);
delay(1000);
show_help();
pinMode(33, INPUT_PULLUP);
audioLogger = &Serial;
file = new AudioFileSourcePROGMEM( tin_wav, sizeof(tin_wav) );
// out = new AudioOutputI2S(0, 1); // use ESP32-internal DAC channel 1 (pin25)
out = new AudioOutputI2S();
out -> SetGain(0.05); // volume quite low
out -> SetPinout(26, 25, 22);
count = wait;
Serial.print("WAV starts...");
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
void loop() {
if (wav->isRunning())
if (!wav->loop()) {
wav->stop();
Serial.println("done.");
delete file;
delete wav;
}
char ch;
if (Serial.available() > 0) {
ch = Serial.read(); // some serial input, using first character
while (Serial.available())
Serial.read();
Serial.println("--> serial trigger");
if ((ch >= '0') && (ch <= '9')) { // Volume: '0' - '9'
float vol = (float)(ch - '0') / 20; // volume 5 = 1/4
out -> SetGain(vol);
Serial.print("vol: ");
Serial.println(vol);
file = new AudioFileSourcePROGMEM( feedback_wav, sizeof(feedback_wav) );
wav = new AudioGeneratorWAV();
wav->begin(file, out);
} else if (ch == 's') { // speed up timer / shortcut
count = 1;
previousMillis = millis();
Serial.println("shortcut");
} else if (ch == '?')
show_help();
else {
if (ch == 'b')
file = new AudioFileSourcePROGMEM( bell_wav, sizeof(bell_wav) );
else if (ch == 'B')
file = new AudioFileSourcePROGMEM( bowl_wav, sizeof(bowl_wav) );
else if (ch == 'c')
file = new AudioFileSourcePROGMEM( clock_wav, sizeof(clock_wav) );
else if (ch == 'd')
file = new AudioFileSourcePROGMEM( dingdong_wav, sizeof(dingdong_wav) );
else if (ch == 'f')
file = new AudioFileSourcePROGMEM( feedback_wav, sizeof(feedback_wav) );
else if (ch == 'g')
file = new AudioFileSourcePROGMEM( gong_wav, sizeof(gong_wav) );
else if (ch == 'h')
file = new AudioFileSourcePROGMEM( horn_wav, sizeof(horn_wav) );
else if (ch == 'l')
file = new AudioFileSourcePROGMEM( laser_wav, sizeof(laser_wav) );
else if (ch == 'p')
file = new AudioFileSourcePROGMEM( power_wav, sizeof(power_wav) );
else if (ch == 't')
file = new AudioFileSourcePROGMEM( tin_wav, sizeof(tin_wav) );
else
file = new AudioFileSourcePROGMEM( over_wav, sizeof(over_wav) );
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
}
if (digitalRead(33) == 0) { // todo: #define pin
delay(100);
count = wait; // restart timer
file = new AudioFileSourcePROGMEM( tin_wav, sizeof(tin_wav) );
wav = new AudioGeneratorWAV();
Serial.println("--> manual trigger");
wav->begin(file, out);
delay(500); // block and debounce
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
count--;
if (count > 0) {
Serial.print("waiting: ");
Serial.println(count); // show timer status
} else {
Serial.println("--> timing trigger");
count = wait; // restart timer
file = new AudioFileSourcePROGMEM( bowl_wav, sizeof(bowl_wav) );
wav = new AudioGeneratorWAV();
Serial.print("WAV starts...\n");
wav->begin(file, out);
}
}
}