aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-08-28 19:03:17 +0100
committerdakkar <dakkar@thenautilus.net>2020-08-28 19:03:17 +0100
commit4ae0383e22f5cc8b0a2c5bf9cb96521fb292b8ce (patch)
treeea2ef5b9c4bca0f1a67b5aa4b8b7911d353dfe2f
parentsounds not-completely terrible (diff)
downloadlego-piano-4ae0383e22f5cc8b0a2c5bf9cb96521fb292b8ce.tar.gz
lego-piano-4ae0383e22f5cc8b0a2c5bf9cb96521fb292b8ce.tar.bz2
lego-piano-4ae0383e22f5cc8b0a2c5bf9cb96521fb292b8ce.zip
move sound rendering inside delay waiting for sensor
-rw-r--r--esp32/lego-piano.ino26
1 files changed, 16 insertions, 10 deletions
diff --git a/esp32/lego-piano.ino b/esp32/lego-piano.ino
index c6d33b8..7901279 100644
--- a/esp32/lego-piano.ino
+++ b/esp32/lego-piano.ino
@@ -158,7 +158,22 @@ void loop() {
#endif
enableLed(currentLed);
- delay(1);
+ unsigned long t = millis();
+
+ int toFill = buffer.maxSize() - buffer.size();
+ if (toFill > 100) {
+ tsf_render_short(g_TinySoundFont, intermediateBuffer, toFill, 0);
+ noInterrupts();
+ for (int i=0;i<toFill;++i) {
+ buffer.push(intermediateBuffer[i]);
+ }
+ interrupts();
+ }
+
+ while (millis() == t) {
+ delayMicroseconds(100);
+ }
+
if (sense(currentLed)) { // currently pressed
if (!pressed[currentLed]) { // was not pressed previously?
Serial.print(currentLed);
@@ -185,13 +200,4 @@ void loop() {
currentLed = (currentLed+1)%(row_count*col_count);
- int toFill = buffer.maxSize() - buffer.size();
- if (toFill > 100) {
- tsf_render_short(g_TinySoundFont, intermediateBuffer, toFill, 0);
- noInterrupts();
- for (int i=0;i<toFill;++i) {
- buffer.push(intermediateBuffer[i]);
- }
- interrupts();
- }
} \ No newline at end of file