From d8723b0df47552624e36aeddfe34e5dd32f1fd8c Mon Sep 17 00:00:00 2001 From: midilab Date: Sat, 24 Sep 2022 06:59:12 -0400 Subject: [PATCH] add a guard on getTempo to avoid slave calculations before buffer gets full --- src/uClock.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/uClock.cpp b/src/uClock.cpp index 147fe1e..3ce5c0b 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -244,6 +244,10 @@ float uClockClass::getTempo() { if (mode == EXTERNAL_CLOCK) { uint32_t acc = 0; + // wait the buffer get full + if (ext_interval_buffer[EXT_INTERVAL_BUFFER_SIZE-1] == 0) { + return tempo; + } for (uint8_t i=0; i < EXT_INTERVAL_BUFFER_SIZE; i++) { acc += ext_interval_buffer[i]; }