aboutsummaryrefslogtreecommitdiff
path: root/esp32/lego-piano.ino
diff options
context:
space:
mode:
Diffstat (limited to 'esp32/lego-piano.ino')
-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