-
Notifications
You must be signed in to change notification settings - Fork 0
/
gong_04_cfg.ino
240 lines (205 loc) · 7.1 KB
/
gong_04_cfg.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
gong-04.cfg - Achtsamkeit-Glocke
Jens, 2021-02-28
MIT License
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
+---------------+
|o ANT o|
|o ___________ o|
|o o|
|o o|
|o D22o|- I2S
I2S -|oD25 o|
I2S -|oD26 o|
|o D18o|- Vol
key -|oD33 o|
|o D10o|- Snd
|o D9o|- Snd
|o o|
|o o|
|o o|
|o o|
|o o|
-4k7R--|oIO0 o|
|------|o3V3 ENo|
|oGND GNDo|
|o5V |USB| 3V3o|
+-----+---+-----+
pull-up IO0 for power-up reset
*/
//#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"
// manual trigger
#define TRIGGER 33
// config pins
#define SNDCFG1 9
#define SNDCFG2 10
#define SNDVOL 18
// non-blocking timer
unsigned long previousMillis = 0;
const unsigned long interval = 60000; // 1 min
const int wait = 60; // 60 min
int count = 0;
AudioGeneratorWAV *wav;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;
const char helpstr[] = "\
\nAchtsamkeits-Glocke\n\
BCGH - sounds used\n\
bflpto - other sounds\n\
0 - sound off\n\
1..9 - volume\n\
T - show timer\n\
s - speed up timer\n\
! - Reset\n\
? - help\n";
void setup() {
// WiFi.mode(WIFI_OFF);
Serial.begin(115200);
delay(1000);
Serial.println(helpstr);
// input pins
pinMode(TRIGGER, INPUT_PULLUP);
pinMode(SNDCFG1, INPUT_PULLUP);
pinMode(SNDCFG2, INPUT_PULLUP);
pinMode(SNDVOL, 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();
if (digitalRead(SNDVOL)) // pin D18
out -> SetGain(0.1); // volume quote low
else
out -> SetGain(0.05); // volume very 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;
char fb = ' '; // neutral feedback, no sound
if (Serial.available() > 0) {
ch = Serial.read(); // some serial input, using first character
while (Serial.available())
Serial.read();
Serial.print("--> serial input: ");
Serial.println(ch);
if (ch < ' ') // drop control characters
;
else if ((ch >= '0') && (ch <= '9')) { // Volume: '0' - '9'
float vol = (float)(ch - '0') / 25;
out -> SetGain(vol);
Serial.print("vol: ");
Serial.println(vol);
fb = '+';
} else if (ch == 's') { // speed up timer / shortcut
count = 1;
previousMillis = millis();
Serial.println("shortcut");
fb = '+';
} else if (ch == '?') { // help
Serial.println(helpstr);
} else if (ch == 'T') {
Serial.print("timer: "); // show time left
Serial.println(count);
} else if (ch == '!') {
Serial.println("reset..."); // reset ESP32
Serial.println(".");
Serial.println(".");
Serial.println(".");
ESP.restart();
} else {
fb = '#'; // play selected sound
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
fb = '-'; // ... no sound, negative feedback
}
if (fb != ' ') {
if (fb == '+')
file = new AudioFileSourcePROGMEM( feedback_wav, sizeof(feedback_wav) );
if (fb == '-')
file = new AudioFileSourcePROGMEM( over_wav, sizeof(over_wav) );
wav = new AudioGeneratorWAV();
wav->begin(file, out);
}
} // serial input
if (digitalRead(TRIGGER) == 0) {
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
if (digitalRead(SNDCFG1)) // pin d9
if (digitalRead(SNDCFG2)) // pin 10
file = new AudioFileSourcePROGMEM( bowl_wav, sizeof(bowl_wav));
else
file = new AudioFileSourcePROGMEM( clock_wav, sizeof(clock_wav));
else if (digitalRead(SNDCFG2))
file = new AudioFileSourcePROGMEM( gong_wav, sizeof(gong_wav));
else
file = new AudioFileSourcePROGMEM( horn_wav, sizeof(horn_wav));
wav = new AudioGeneratorWAV();
Serial.print("WAV starts...\n");
wav->begin(file, out);
}
}
}