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.

95 lines
1.4 KiB
C++

/*
PMA770Relay Alpha2
dewdude@gmail.com - 29-12-2019
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int latchPin = 11;
int clockPin = 9;
int dataPin = 12;
int matrix = A0;
byte out = 0;
int mx = 0;
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();
}
void setTape1()
{
DontCrossTheStreams();
bitSet(out,6);
updateShiftRegister();
}
void setAUX()
{
DontCrossTheStreams();
bitSet(out,5);
updateShiftRegister();
}
void setTune()
{
DontCrossTheStreams();
bitSet(out,4);
updateShiftRegister();
}
void setPh1()
{
DontCrossTheStreams();
bitSet(out,3);
bitSet(out,1);
updateShiftRegister();
}
void setPh2()
{
DontCrossTheStreams();
bitSet(out,3);
bitSet(out,2);
updateShiftRegister();
}
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
bitSet(out,5);
updateShiftRegister();
}
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();
delay(200);
}