From 1d619775db1f50007825573a4ecb357ef7203c0d Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Tue, 19 Sep 2023 10:59:17 +0200 Subject: [PATCH] Code cleanup. --- MIDI-Host-Adapter.ino | 49 +++++++++++++------------------------------ 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/MIDI-Host-Adapter.ino b/MIDI-Host-Adapter.ino index be43144..5a8497e 100644 --- a/MIDI-Host-Adapter.ino +++ b/MIDI-Host-Adapter.ino @@ -59,21 +59,8 @@ void setup() { tm.displayBegin(); tm.brightness(BRIGHTNESS); - //tm.DisplayStr("HLLOWRLD", 0); - uint8_t tmp_channel = EEPROM.read(EEPROM_ADDRESS); - if (tmp_channel & 0xf0 != 0xf0) { - actual_channel = 1; -#if defined(DEBUG) - Serial.println("Setting channel to 1"); -#endif - } else { - actual_channel = 0x0f & tmp_channel; -#if defined(DEBUG) - Serial.print("Reading channel from EEPROM: "); - Serial.println(actual_channel, DEC); -#endif - } + actual_channel=read_channel_from_eeprom(); new_channel = actual_channel; pinMode(MIDI_CH_BIT3, OUTPUT); @@ -83,8 +70,6 @@ void setup() { SetMidiChannel(INITIAL_MIDI_CHANNEL); - //Scrolling_Text(); - tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight); #if defined(DEBUG) @@ -161,23 +146,19 @@ void SetMidiChannel(uint8_t channel) { digitalWrite(MIDI_CH_BIT3, channel & 0x08); } -void Scrolling_Text(void) { - char textScroll[] = " 42 IS THE ANSWER "; - unsigned long previousMillis_display = 0; // will store last time display was updated - const long interval_display = 150; // interval at which to update display (milliseconds) - - while (42 == 42) { - tm.DisplayStr(textScroll, 0); - unsigned long currentMillis = millis(); - // update data every interval_display delay - if (currentMillis - previousMillis_display >= interval_display) { - previousMillis_display = currentMillis; - if (strlen(textScroll) > 0) { - memmove(textScroll, textScroll + 1, strlen(textScroll)); // delete first char in array. - } else { - return; - } - } +uint8_t read_channel_from_eeprom(void) { + uint8_t tmp_channel = EEPROM.read(EEPROM_ADDRESS); + if (tmp_channel & 0xf0 != 0xf0) { + actual_channel = 1; +#if defined(DEBUG) + Serial.println("Setting channel to 1"); +#endif + } else { + actual_channel = 0x0f & tmp_channel; +#if defined(DEBUG) + Serial.print("Reading channel from EEPROM: "); + Serial.println(actual_channel, DEC); +#endif } } @@ -187,4 +168,4 @@ void printBinary(uint32_t value, uint8_t len) { Serial.print((char)('0' + ((value >> (b - 1)) & 1))); } } -#endif \ No newline at end of file +#endif