/* HiFiLOGIX 0.1.4 dewdude@gmail.com - 04-JAN-2020 */ #include #include #include U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0); // const char *inputs[] = {"TAPE-2","TAPE-1","AUX","TUNER","PHONO-2","PHONO-1"}; // int i = 0; int latchPin = 11; int clockPin = 9; int dataPin = 12; int IRin = 7; int srEnable = 5; int matrix = A0; byte out = 0; int mx = 0; IRrecv remote(IRin); decode_results ircode; void logo() { u8g2.clearBuffer(); u8g2.setFont(u8g2_font_fewture_tr); u8g2.drawStr(15,14,"HiFiLOGIX"); u8g2.setFont(u8g2_font_freedoomr10_tu); u8g2.drawStr(14,30,"DENON PMA-770"); u8g2.sendBuffer(); u8g2.setFont(u8g2_font_logisoso28_tr); } /* void inputdisp() { u8g2.clearBuffer(); u8g2.drawStr(x,30,inputs[i]); u8g2.sendBuffer(); } */ void updateShiftRegister() { digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, out); digitalWrite(latchPin, HIGH); } void DontCrossTheStreams() { out = 0; updateShiftRegister(); // Don't cross the streams! } void setTape2() { DontCrossTheStreams(); bitSet(out,6); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(10,30,"TAPE-2"); u8g2.sendBuffer(); } void setTape1() { DontCrossTheStreams(); bitSet(out,5); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(10,30,"TAPE-1"); u8g2.sendBuffer(); } void setAUX() { DontCrossTheStreams(); bitSet(out,4); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(32,30,"AUX"); u8g2.sendBuffer(); } void setTune() { DontCrossTheStreams(); bitSet(out,3); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(18,30,"TUNER"); u8g2.sendBuffer(); } void setPh1() { DontCrossTheStreams(); bitSet(out,2); bitSet(out,1); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(1,30,"PHONO-2"); u8g2.sendBuffer(); } void setPh2() { DontCrossTheStreams(); bitSet(out,2); bitSet(out,0); updateShiftRegister(); u8g2.clearBuffer(); u8g2.drawStr(1,30,"PHONO-1"); u8g2.sendBuffer(); } void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(srEnable, OUTPUT); u8g2.begin(); remote.enableIRIn(); logo(); delay(2000); setAUX(); digitalWrite(srEnable,LOW); } void loop() { int mx = analogRead(matrix); if (mx > 100 && mx < 200) setTape2(); if (mx > 500 && mx < 600) setTape1(); if (mx > 900 && mx < 950) setAUX(); if (mx > 1000) setTune(); if (mx > 820 && mx < 899) setPh1(); if (remote.decode(&ircode)) { switch(ircode.value){ case 0xFF6897: setTape2(); break; case 0xFF9867: setTape1(); break; case 0xFFB04F: setAUX(); break; case 0xFF30CF: setTune(); break; case 0xFF18E7: setPh1(); break; case 0xFF7A85: setPh2(); break; } remote.resume(); } delay(200); }