Several fixes.

main
Holger Wirtz 9 months ago
parent c5dd7c5dea
commit 268feec514
  1. 22
      MIDI-Host-Adapter.ino

@ -31,13 +31,13 @@
#define MIDI_CH_BIT1 3
#define MIDI_CH_BIT0 2
bool swap_nibbles = false;
bool swap_nibbles = true;
bool high_freq = false;
#define BRIGHTNESS 6
#define INITIAL_MIDI_CHANNEL 1
#define BUTTON_DEBOUNCE_TIME_MS 50
#define BUTTON_DOUBLE_PRESS_MS 200
#define BUTTON_DEBOUNCE_TIME_MS 150
#define BUTTON_DOUBLE_PRESS_MS 250
#define BLINK_FREQUENCY_MS 500
#define EEPROM_ADDRESS 0x42
@ -47,6 +47,7 @@ elapsedMillis button_debounce_timer;
elapsedMillis blink_timer;
elapsedMillis double_press_timer;
uint8_t actual_channel;
uint8_t new_channel;
void setup() {
Serial.begin(9600);
@ -67,6 +68,7 @@ void setup() {
Serial.print("Reading channel from EEPROM: ");
Serial.println(actual_channel, DEC);
}
new_channel = actual_channel;
pinMode(MIDI_CH_BIT3, OUTPUT);
pinMode(MIDI_CH_BIT2, OUTPUT);
@ -84,7 +86,6 @@ void setup() {
void loop() {
uint8_t button;
static uint8_t new_channel;
button = tm.ReadKey16();
@ -93,6 +94,7 @@ void loop() {
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);
@ -101,16 +103,17 @@ void loop() {
Serial.print("Button twice: ");
Serial.println(button, DEC);
actual_channel = new_channel;
EEPROM.update(EEPROM_ADDRESS, 0xf0 & actual_channel);
EEPROM.update(EEPROM_ADDRESS, 0xf0 | actual_channel);
SetMidiChannel(actual_channel);
double_press_timer = 0;
} else if (actual_channel != new_channel)
} else 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);
}
void SetMidiChannel(uint8_t channel) {
@ -133,8 +136,7 @@ void SetMidiChannel(uint8_t channel) {
}
void printBinary(uint32_t value, uint8_t len) {
for (len; len >= 0; len--) {
Serial.print((char)('0' + ((value >> len) & 1)));
for (uint8_t b = len; b > 0; --b) {
Serial.print((char)('0' + ((value >> (b - 1)) & 1)));
}
Serial.println();
}
Loading…
Cancel
Save