Some optimizations.

main
Holger Wirtz 9 months ago
parent 1f4b325e02
commit bbaeb25b54
  1. 41
      MIDI-Host-Adapter.ino

@ -45,7 +45,6 @@ bool high_freq = false;
TM1638plus_Model2 tm(STROBE_TM, CLOCK_TM, DIO_TM, swap_nibbles, high_freq);
elapsedMillis button_debounce_timer;
elapsedMillis blink_timer;
elapsedMillis double_press_timer;
uint8_t actual_channel;
uint8_t new_channel;
@ -89,31 +88,33 @@ void loop() {
button = tm.ReadKey16();
if (button > 0 && button_debounce_timer > BUTTON_DEBOUNCE_TIME_MS && double_press_timer > BUTTON_DOUBLE_PRESS_MS) {
// Button pressed once
Serial.print("Button once: ");
Serial.println(button, DEC);
button_debounce_timer = 0;
double_press_timer = 0;
blink_timer = 0;
new_channel = button;
tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight);
} else if (button > 0 && button_debounce_timer > BUTTON_DEBOUNCE_TIME_MS && double_press_timer < BUTTON_DOUBLE_PRESS_MS && button == new_channel) {
// Button pressed twice
Serial.print("Button twice: ");
Serial.println(button, DEC);
actual_channel = new_channel;
EEPROM.update(EEPROM_ADDRESS, 0xf0 | actual_channel);
SetMidiChannel(actual_channel);
} else if (actual_channel != new_channel) {
if (button > 0 && button != actual_channel && button_debounce_timer > BUTTON_DEBOUNCE_TIME_MS) {
if (button != new_channel) {
// Button pressed once
Serial.print("Button once: ");
Serial.println(button, DEC);
button_debounce_timer = 0;
blink_timer = 0;
new_channel = button;
tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight);
} else {
// Button pressed twice
Serial.print("Button twice: ");
Serial.println(button, DEC);
actual_channel = new_channel;
EEPROM.update(EEPROM_ADDRESS, 0xf0 | actual_channel);
SetMidiChannel(actual_channel);
}
}
if (actual_channel != new_channel) {
if (blink_timer > BLINK_FREQUENCY_MS) {
blink_timer = 0;
tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight);
} else if (blink_timer > BLINK_FREQUENCY_MS / 2) {
tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight);
}
} else
tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight);
} else tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight);
}
void SetMidiChannel(uint8_t channel) {

Loading…
Cancel
Save