You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
2.4 KiB
Arduino

4 years ago
/*
PMA770Relay 0.1.3
4 years ago
dewdude@gmail.com - 30-12-2019
4 years ago
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
4 years ago
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;
int IRin = 7;
int srEnable = 5;
4 years ago
int matrix = A0;
byte out = 0;
int mx = 0;
IRrecv remote(IRin);
decode_results ircode;
LiquidCrystal_I2C lcd(0x27,16,2);
4 years ago
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
4 years ago
shiftOut(dataPin, clockPin, LSBFIRST, out);
digitalWrite(latchPin, HIGH);
}
void DontCrossTheStreams()
4 years ago
{
out = 0;
updateShiftRegister();
// Don't cross the streams!
}
void setTape2()
{
DontCrossTheStreams();
bitSet(out,7);
4 years ago
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("TAPE-2 ");
4 years ago
}
4 years ago
void setTape1()
{
DontCrossTheStreams();
bitSet(out,6);
4 years ago
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("TAPE-1 ");
4 years ago
}
4 years ago
void setAUX()
{
DontCrossTheStreams();
bitSet(out,5);
4 years ago
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("AUX ");
4 years ago
}
4 years ago
void setTune()
{
DontCrossTheStreams();
bitSet(out,4);
4 years ago
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("TUNER ");
4 years ago
}
4 years ago
void setPh1()
{
DontCrossTheStreams();
bitSet(out,3);
bitSet(out,0);
4 years ago
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("PHONO-1 ");
4 years ago
}
void setPh2()
{
DontCrossTheStreams();
bitSet(out,3);
bitSet(out,1);
updateShiftRegister();
lcd.setCursor(7, 1);
lcd.print("PHONO-2 ");
}
4 years ago
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);
4 years ago
}
void loop() {
4 years ago
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();
}
4 years ago
delay(200);
}