/* PMA770Relay 0.1.3 dewdude@gmail.com - 30-12-2019 */ #include #include #include 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; LiquidCrystal_I2C lcd(0x27,16,2); 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,7); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("TAPE-2 "); } void setTape1() { DontCrossTheStreams(); bitSet(out,6); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("TAPE-1 "); } void setAUX() { DontCrossTheStreams(); bitSet(out,5); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("AUX "); } void setTune() { DontCrossTheStreams(); bitSet(out,4); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("TUNER "); } void setPh1() { DontCrossTheStreams(); bitSet(out,3); bitSet(out,0); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("PHONO-1 "); } void setPh2() { DontCrossTheStreams(); bitSet(out,3); bitSet(out,1); updateShiftRegister(); lcd.setCursor(7, 1); lcd.print("PHONO-2 "); } void setup() { pinMode(latchPin, OUTPUT); pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(srEnable, OUTPUT); remote.enableIRIn(); bitSet(out,5); lcd.init(); lcd.backlight(); lcd.home(); lcd.setCursor(0, 0); lcd.print("Denon PMA-770"); lcd.setCursor(0, 1); lcd.print("Input: AUX"); updateShiftRegister(); 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); }