From c897802fb35dc754095193ae09033d6cae2603bf Mon Sep 17 00:00:00 2001 From: midilab Date: Wed, 28 Sep 2022 08:28:24 -0400 Subject: [PATCH] change example printBPM function call per a String() call --- .../LeonardoUsbSlaveMidiClockMonitor.ino | 24 ++++++------------- .../TeensyUsbSlaveMidiClockMonitor.ino | 24 ++++++------------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino b/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino index cda6b6a..7b00f44 100644 --- a/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino +++ b/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino @@ -28,7 +28,6 @@ U8X8 * u8x8; #define MIDI_START 0xFA #define MIDI_STOP 0xFC -char bpm_str[8]; float bpm = 126.0; uint8_t bpm_blink_timer = 1; uint8_t clock_state = 1; @@ -113,21 +112,6 @@ void setup() { //uClock.start(); } -void printBpm(float _bpm, uint8_t col, uint8_t line) { - // clear bpm buffer - memset(bpm_str, ' ', 7); - // min width=3, precision=2 - dtostrf(_bpm, 3, 1, bpm_str); - bpm_str[5] = '\0'; - u8x8->drawUTF8(col, line, bpm_str); - u8x8->drawUTF8(col+5, line, "bpm"); - // clear display ghost number for 2 digit - // coming from 3 digit bpm changes - if (_bpm < 100) { - u8x8->drawUTF8(col+4, line, " "); - } -} - void loop() { while(MIDI.read()) {} // DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC @@ -135,7 +119,13 @@ void loop() { // read Serial as fast as we can on the loop if (bpm != uClock.getTempo()) { bpm = uClock.getTempo(); - printBpm(bpm, 8, 7); + u8x8->drawUTF8(8, 7, String(bpm, 1).c_str()); + u8x8->drawUTF8(8+5, 7, "bpm"); + // clear display ghost number for 2 digit + // coming from 3 digit bpm changes + if (bpm < 100) { + u8x8->drawUTF8(8+4, 7, " "); + } } if (clock_state != uClock.state) { clock_state = uClock.state; diff --git a/examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino b/examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino index 74f18d7..2621fac 100644 --- a/examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino +++ b/examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino @@ -29,7 +29,6 @@ IntervalTimer teensyTimer; #define MIDI_START 0xFA #define MIDI_STOP 0xFC -char bpm_str[8]; float bpm = 126; uint8_t bpm_blink_timer = 1; uint8_t clock_state = 1; @@ -122,25 +121,16 @@ void handleMidiInput() { } } -void printBpm(float _bpm, uint8_t col, uint8_t line) { - // clear bpm buffer - memset(bpm_str, ' ', 7); - // min width=3, precision=2 - dtostrf(_bpm, 3, 1, bpm_str); - bpm_str[5] = '\0'; - u8x8->drawUTF8(col, line, bpm_str); - u8x8->drawUTF8(col+5, line, "bpm"); - // clear display ghost number for 2 digit - // coming from 3 digit bpm changes - if (_bpm < 100) { - u8x8->drawUTF8(col+4, line, " "); - } -} - void loop() { if (bpm != uClock.getTempo()) { bpm = uClock.getTempo(); - printBpm(bpm, 8, 7); + u8x8->drawUTF8(8, 7, String(bpm, 1).c_str()); + u8x8->drawUTF8(8+5, 7, "bpm"); + // clear display ghost number for 2 digit + // coming from 3 digit bpm changes + if (bpm < 100) { + u8x8->drawUTF8(8+4, 7, " "); + } } if (clock_state != uClock.state) { clock_state = uClock.state;