/* HiFiLOGIX EEPROM BETA (0.1.8 Base) dewdude@gmail.com - 08-JAN-2019 !!! IMPORTANT !!! IF YOU HAVE DATA AT ADDRESSES 1020 - 1023, THIS SKETCH WILL CHANGE IT. IF YOUR EEPROM IS SMALLER, YOU WILL NEED TO CHANGE THE ADDRESSES. THIS CURRENTLY WRITES TO THE EEPROM EVERY SOURCE CHANGE. Address 1020 stores the byte to be sent to the shift register. Address 1021 stores the x offset for the display. Address 1022 contains the index of the input string array. Address 1023 contains the letter "T" if defaults exist. On boot the script looks for the letter "T" at address 1023. If it exists this is supposed to indicate it's been initialized and it will continue with the main setup loop. If not, it writes default values to locations 1020 - 1022 and writes T to 1023. During the setup loop, the values stored at 1020 - 1022 are fed as arguments to DontCrossTheStreams. I could probably do this with a bunch of if loops to read a single byte and translate that in to the rest...but I don't know how that would affect the memory. */ #include #include #include #include #define di 1022 #define dx 1021 #define db 1020 #include "logo.h" // XBMP data for logo. U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); const char *inputs[] = {"TAPE-2","TAPE-1","AUX","TUNER","PHONO-2","PHONO-1"}; int latchPin = 11; int clockPin = 9; int dataPin = 12; int IRin = 7; int blanking = 5; int matrix = A0; IRrecv remote(IRin); decode_results ircode; void DontCrossTheStreams(byte op, int x, int i) // There's something very important I forgot to tell you. {// Don't cross the streams. // Why? digitalWrite(latchPin, LOW); // It would be bad. shiftOut(dataPin, clockPin, LSBFIRST, op); // What do you mean, bad? digitalWrite(latchPin, HIGH); // Imagine all life as you know u8g2.clearBuffer(); // it stopping instaneously u8g2.drawStr(x,30,inputs[i]); // and every molecule in u8g2.sendBuffer(); // your body exploding EEPROM.update(db, op); // at the speed of light. EEPROM.update(dx, x); // Total protonic reversal. EEPROM.update(di, i); // That's bad. // Important safety tip, thanks Egon. } void eeprominit() { if (EEPROM.read(1023) == 'T') { return; } else { EEPROM.write(db, 16); EEPROM.write(dx, 32); EEPROM.write(di, 2); EEPROM.write(1023, 'T'); } } void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(blanking, OUTPUT); eeprominit(); u8g2.begin(); remote.enableIRIn(); u8g2.firstPage(); // Logo is now bitmapped and since I only call it do { // once, it doesn't need it's own function. u8g2.drawXBMP(14,4,hifilogix_width,hifilogix_height,hifilogix_bits); } while ( u8g2.nextPage() ); delay(2000); // It takes the Denon about 4.5 seconds to kick speakers on. u8g2.setFont(u8g2_font_logisoso28_tr); // Moved here since logo is bitmap. DontCrossTheStreams(EEPROM.read(db),EEPROM.read(dx),EEPROM.read(di)); // THIS IS NO LONGER STATIC IN THE BETA! (yay.) digitalWrite(blanking,HIGH); // Now drives a logic inverter. } void loop() { int mx = analogRead(matrix); byte icode = 0; // I changed how I handed the inputs. if (remote.decode(&ircode)) { icode = ircode.value; remote.resume(); } // I don't know if it improves things, but I sure like how much smaller this section is. if ((mx > 100 && mx < 200) || (icode == 0x97)) DontCrossTheStreams(64,10,0); // The code I originally used to figure out my if ((mx > 500 && mx < 600) || (icode == 0x67)) DontCrossTheStreams(32,10,1); // remote codes returned 3 bytes in hex. I can't if ((mx > 900 && mx < 950) || (icode == 0x4F)) DontCrossTheStreams(16,32,2); // remember what that code was, but I only need if ((mx > 1000) || (icode == 0xCF)) DontCrossTheStreams(8,18,3); // the last bit with the remote I'm using. if ((mx > 820 && mx < 899) || (icode == 0xE7)) DontCrossTheStreams(6,1,4); // I'm working on making the bare-bones utility I if ((mx > 700 && mx < 800) || (icode == 0x85)) DontCrossTheStreams(5,1,5); // wrote a bit more user-friendly. delay(200); }