From 793a74ce7944255e45402049b6f9e180eeff95aa Mon Sep 17 00:00:00 2001 From: midilab Date: Mon, 26 Dec 2022 08:31:20 -0500 Subject: [PATCH] change esp32 example to avoid freezes over serial usage on isr --- .../ESP32UartMasterMidiClock.ino | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/ESP32UartMasterMidiClock/ESP32UartMasterMidiClock.ino b/examples/ESP32UartMasterMidiClock/ESP32UartMasterMidiClock.ino index 9de6708..f83952b 100644 --- a/examples/ESP32UartMasterMidiClock/ESP32UartMasterMidiClock.ino +++ b/examples/ESP32UartMasterMidiClock/ESP32UartMasterMidiClock.ino @@ -18,6 +18,8 @@ // the blue led #define LED_BUILTIN 2 +volatile bool _midi_clk_income = false; + uint8_t bpm_blink_timer = 1; void handle_bpm_led(uint32_t tick) { @@ -37,6 +39,7 @@ void handle_bpm_led(uint32_t tick) void ClockOut96PPQN(uint32_t tick) { // Send MIDI_CLOCK to external gears //Serial.write(MIDI_CLOCK); + _midi_clk_income = true; handle_bpm_led(tick); } @@ -71,5 +74,11 @@ void setup() { // Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment... void loop() { - + // watch for income signal from uClock to fire the clock over midi + if (_midi_clk_income) { + Serial.write(MIDI_CLOCK); + noInterrupts(); + _midi_clk_income = false; + interrupts(); + } }