changes on leonardo usb midi monitor example for compilance on version 0.9.4

pull/7/head
midilab 4 years ago
parent 5847d7e147
commit f7870cad2e
  1. 37
      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;

Loading…
Cancel
Save