Don't cross the streams!

master
Jay 5 years ago
parent 864f5abfe6
commit c12edf1cac

@ -1,9 +1,11 @@
/* /*
Input Relay Alpha PMA770Relay Alpha2
dewdude@gmail.com - 28-12-2019 dewdude@gmail.com - 29-12-2019
*/ */
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int latchPin = 11; int latchPin = 11;
int clockPin = 9; int clockPin = 9;
@ -12,69 +14,81 @@ int matrix = A0;
byte out = 0; byte out = 0;
int mx = 0; int mx = 0;
void updateShiftRegister() void updateShiftRegister()
{ {
digitalWrite(latchPin,LOW); digitalWrite(latchPin,LOW);
shiftOut(dataPin, clockPin, LSBFIRST, out); shiftOut(dataPin, clockPin, LSBFIRST, out);
digitalWrite(latchPin, HIGH); digitalWrite(latchPin, HIGH);
} }
void setTape2()
void DontCrossTheStreams()
{ {
out = 0; out = 0;
updateShiftRegister(); updateShiftRegister();
bitSet(out,5); // Don't cross the streams!
}
void setTape2()
{
DontCrossTheStreams();
bitSet(out,7);
updateShiftRegister(); updateShiftRegister();
} }
void setTape1() void setTape1()
{ {
out = 0; DontCrossTheStreams();
updateShiftRegister(); bitSet(out,6);
bitSet(out,4);
updateShiftRegister(); updateShiftRegister();
} }
void setAUX() void setAUX()
{ {
out = 0; DontCrossTheStreams();
updateShiftRegister(); bitSet(out,5);
bitSet(out,3);
updateShiftRegister(); updateShiftRegister();
} }
void setTune() void setTune()
{ {
out = 0; DontCrossTheStreams();
updateShiftRegister(); bitSet(out,4);
bitSet(out,2);
updateShiftRegister(); updateShiftRegister();
} }
void setPh1() void setPh1()
{ {
out = 0; DontCrossTheStreams();
updateShiftRegister(); bitSet(out,3);
bitSet(out,1); bitSet(out,1);
updateShiftRegister(); updateShiftRegister();
} }
void setPh2()
{
DontCrossTheStreams();
bitSet(out,3);
bitSet(out,2);
updateShiftRegister();
}
void setup() void setup()
{ {
pinMode(latchPin, OUTPUT); pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT); pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT); pinMode(clockPin, OUTPUT);
// Serial.begin(9600); bitSet(out,5);
// Serial.print("Setting default output");
bitSet(out,6);
updateShiftRegister(); updateShiftRegister();
// Serial.print("Scanning Matrix");
} }
void loop() { void loop() {
// put your main code here, to run repeatedly:
int mx = analogRead(matrix); int mx = analogRead(matrix);
if (mx > 100 && mx < 200) setTape2(); if (mx > 100 && mx < 200) setTape2();
if (mx > 500 && mx < 600) setTape1(); if (mx > 500 && mx < 600) setTape1();
if (mx > 900 && mx < 950) setAUX(); if (mx > 900 && mx < 950) setAUX();
if (mx > 1000) setTune(); if (mx > 1000) setTune();
if (mx > 820 && mx < 899) setPh1(); if (mx > 820 && mx < 899) setPh1();
// Serial.println(mx);
delay(200); delay(200);
} }

Loading…
Cancel
Save