fixes for examples on print bpm slave time

pull/19/head
midilab 2 years ago
parent 8a27c0c3d9
commit c2b63d362d
  1. 30
      examples/LeonardoUsbSlaveMidiClockMonitor/LeonardoUsbSlaveMidiClockMonitor.ino
  2. 29
      examples/TeensyUsbSlaveMidiClockMonitor/TeensyUsbSlaveMidiClockMonitor.ino

@ -114,21 +114,19 @@ void setup() {
} }
void printBpm(float _bpm, uint8_t col, uint8_t line) { void printBpm(float _bpm, uint8_t col, uint8_t line) {
int b = (int)_bpm; uint8_t str_idx = 6;
//int c = (int)((_bpm-b)*100); // clear bpm buffer
int c = (int)((_bpm-b)*10); memset(bpm_str, ' ', 8);
itoa(b, bpm_str, 10); // min width=3, precision=2
if (b > 99) { dtostrf(_bpm, 3, 2, bpm_str);
bpm_str[6] = '\0';
u8x8->drawUTF8(col, line, bpm_str); u8x8->drawUTF8(col, line, bpm_str);
} else { u8x8->drawUTF8(col+7, line, "bpm");
bpm_str[2] = "\0"; // clear display ghost number for 2 digit
u8x8->drawUTF8(col, line, " "); // coming from 3 digit bpm changes
u8x8->drawUTF8(col+1, line, bpm_str); if (_bpm < 100) {
u8x8->drawUTF8(col+5, line, " ");
} }
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() { void loop() {
@ -138,14 +136,14 @@ void loop() {
// read Serial as fast as we can on the loop // read Serial as fast as we can on the loop
if (bpm != uClock.getTempo()) { if (bpm != uClock.getTempo()) {
bpm = uClock.getTempo(); bpm = uClock.getTempo();
printBpm(bpm, 8, 7); printBpm(bpm, 6, 7);
} }
if (clock_state != uClock.state) { if (clock_state != uClock.state) {
clock_state = uClock.state; clock_state = uClock.state;
if (clock_state >= 1) { if (clock_state >= 1) {
u8x8->drawUTF8(0, 7, "playing"); u8x8->drawUTF8(0, 7, "play");
} else { } else {
u8x8->drawUTF8(0, 7, "stoped "); u8x8->drawUTF8(0, 7, "stop");
} }
} }
if (clock_mode != uClock.getMode()) { if (clock_mode != uClock.getMode()) {

@ -123,33 +123,32 @@ void handleMidiInput() {
} }
void printBpm(float _bpm, uint8_t col, uint8_t line) { void printBpm(float _bpm, uint8_t col, uint8_t line) {
int b = (int)_bpm; uint8_t str_idx = 6;
int c = (int)((_bpm-b)*10); // clear bpm buffer
itoa(b, bpm_str, 10); memset(bpm_str, ' ', 8);
if (b > 99) { // min width=3, precision=2
dtostrf(_bpm, 3, 2, bpm_str);
bpm_str[6] = '\0';
u8x8->drawUTF8(col, line, bpm_str); u8x8->drawUTF8(col, line, bpm_str);
} else { u8x8->drawUTF8(col+7, line, "bpm");
bpm_str[2] = '\0'; // clear display ghost number for 2 digit
u8x8->drawUTF8(col, line, " "); // coming from 3 digit bpm changes
u8x8->drawUTF8(col+1, line, bpm_str); if (_bpm < 100) {
u8x8->drawUTF8(col+5, line, " ");
} }
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() { void loop() {
if (bpm != uClock.getTempo()) { if (bpm != uClock.getTempo()) {
bpm = uClock.getTempo(); bpm = uClock.getTempo();
printBpm(bpm, 8, 7); printBpm(bpm, 6, 7);
} }
if (clock_state != uClock.state) { if (clock_state != uClock.state) {
clock_state = uClock.state; clock_state = uClock.state;
if (clock_state >= 1) { if (clock_state >= 1) {
u8x8->drawUTF8(0, 7, "playing"); u8x8->drawUTF8(0, 7, "play");
} else { } else {
u8x8->drawUTF8(0, 7, "stoped "); u8x8->drawUTF8(0, 7, "stop");
} }
} }
} }

Loading…
Cancel
Save