From f7870cad2ec0718559a02d94a442de385bae46d9 Mon Sep 17 00:00:00 2001 From: midilab Date: Sun, 1 Nov 2020 14:40:12 -0500 Subject: [PATCH] changes on leonardo usb midi monitor example for compilance on version 0.9.4 --- .../LeonardoUsbSlaveMidiClockMonitor.ino | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino b/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino index 2f0ce50..aa55dae 100644 --- a/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino +++ b/examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino @@ -9,6 +9,12 @@ * - USB-MIDI and MIDIUSB * - u8g2 * - uClock + * + * This example make use of drift values (10, 14) + * respectively for internal and external drift reference. + * This example was tested on a macbook + * runing ableton live 9 as master clock + * * This example code is in the public domain. */ @@ -28,8 +34,8 @@ U8X8 * u8x8; #define MIDI_START 0xFA #define MIDI_STOP 0xFC -char bpm_str[3]; -uint16_t bpm = 126; +char bpm_str[4]; +float bpm = 126.0; uint8_t bpm_blink_timer = 1; uint8_t clock_state = 1; @@ -91,7 +97,8 @@ void setup() { // OLED setup // Please check you oled model to correctly init him // - u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); + //u8x8 = new U8X8_SH1106_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); + u8x8 = new U8X8_SSD1306_128X64_NONAME_HW_I2C(U8X8_PIN_NONE); u8x8->begin(); u8x8->setFont(u8x8_font_pressstart2p_r); u8x8->clear(); @@ -101,7 +108,7 @@ void setup() { // uClock Setup // // fine tunning adjstments for you clock slaves/host setDrift(internal, external) - uClock.setDrift(10); + uClock.setDrift(10, 14); uClock.init(); uClock.setClock96PPQNOutput(ClockOut96PPQN); // For MIDI Sync Start and Stop @@ -110,6 +117,24 @@ void setup() { uClock.setMode(uClock.EXTERNAL_CLOCK); } +void printBpm(float _bpm, uint8_t col, uint8_t line) { + int b = (int)_bpm; + //int c = (int)((_bpm-b)*100); + int c = (int)((_bpm-b)*10); + itoa(b, bpm_str, 10); + if (b > 99) { + u8x8->drawUTF8(col, line, bpm_str); + } else { + bpm_str[2] = "\0"; + u8x8->drawUTF8(col, line, " "); + u8x8->drawUTF8(col+1, line, bpm_str); + } + u8x8->drawUTF8(col+3, line, "."); + itoa(c, bpm_str, 10); + u8x8->drawUTF8(col+4, line, bpm_str); + u8x8->drawUTF8(col+5, line, "bpm"); +} + void loop() { MIDI.read(); // DO NOT ADD MORE PROCESS HERE AT THE COST OF LOSING CLOCK SYNC @@ -117,9 +142,7 @@ void loop() { // read Serial as fast as we can on the loop if (bpm != uClock.getTempo()) { bpm = uClock.getTempo(); - itoa(bpm, bpm_str, 10); - u8x8->drawUTF8(10, 7, bpm_str); - u8x8->drawUTF8(13, 7, "bpm"); + printBpm(bpm, 8, 7); } if (clock_state != uClock.state) { clock_state = uClock.state;