Last active
August 25, 2017 16:39
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int CodeIn;// Gets the serial read | |
int ARRAY_myrecall[8]; | |
int pttButton = 24;// Button to test all annunciations | |
int buttonState = 0; | |
int KpinNo; | |
int Koutpin; | |
String gear, warn, start, batt, vac, oil, fuel, stall, pitot, Bvm; | |
int geari, warni, starti, batti, vaci, oili, fueli, stalli, pitoti, Bvmi; | |
unsigned int warnalarm; | |
unsigned int gearalarm; | |
String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate; | |
void setup(){ | |
Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111"; | |
for (int KoutPin = 22; KoutPin < 70; KoutPin++)// Get these pins ready as inputs | |
{ | |
pinMode(KoutPin, INPUT); | |
digitalWrite(KoutPin, HIGH); | |
} | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
pinMode(7, OUTPUT); | |
pinMode(8, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(pttButton, INPUT_PULLUP); | |
Serial.begin(115200); | |
} | |
void loop() { | |
{INPUTS();} //Check the "keys" section | |
{PUSHTOTEST();} | |
if (Serial.available()) { | |
CodeIn = getChar(); | |
if (CodeIn == '=') {EQUALS();} | |
if (CodeIn == '<') {LESSTHAN();} | |
if (CodeIn == '?') {QUESTION();} | |
if (CodeIn == '/') {SLASH();} | |
} | |
} | |
char getChar() | |
{ | |
while(Serial.available() == 0); | |
return((char)Serial.read()); | |
} | |
void EQUALS(){ | |
CodeIn = getChar(); | |
switch(CodeIn) { | |
case 'A': | |
//Do something | |
break; | |
case 'W': | |
//Do something | |
break; | |
case 'a': | |
//Do something | |
break; | |
//etc etc etc | |
} | |
} | |
void LESSTHAN(){ | |
CodeIn = getChar(); // Get another character | |
switch(CodeIn) {// Now lets find what to do with it | |
case 'b': | |
pitot = ""; | |
pitot += getChar(); | |
pitoti = pitot.toInt(); // convert it to an integer (Thanks Phill) | |
if (pitoti == 1 && Bvmi!=0) {digitalWrite(9, HIGH);} else {digitalWrite(9, LOW);} | |
break; | |
case 'k': | |
start = ""; | |
start += getChar(); | |
starti = start.toInt(); | |
if (starti == 1 && Bvmi!=0) {digitalWrite(3, HIGH);} else {digitalWrite(3, LOW);} | |
break; | |
case 'a': | |
Bvm = ""; | |
Bvm += getChar(); | |
Bvmi = Bvm.toInt(); | |
if (Bvmi!=0 && pitoti==1){digitalWrite(9, HIGH);}else{digitalWrite(9, LOW);} | |
if (Bvmi!=0 && starti==1){digitalWrite(3, HIGH);}else{digitalWrite(3, LOW);} | |
if (Bvmi!=0 && vaci==1){digitalWrite(5, HIGH);}else{digitalWrite(5, LOW);} | |
if (Bvmi!=0 && oili==1){digitalWrite(6, HIGH);}else{digitalWrite(6, LOW);} | |
if (Bvmi!=0 && batti==1){digitalWrite(4, HIGH);}else{digitalWrite(4, LOW);} | |
if (Bvmi!=0 && gearalarm == 1 && warnalarm == 1) {digitalWrite(2, HIGH);}else{digitalWrite(2, LOW);} | |
if (Bvmi!=0 && fueli==1){digitalWrite(7, HIGH);}else{digitalWrite(7, LOW);} | |
if (Bvmi!=0 && stalli==1){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);} | |
} | |
} | |
void QUESTION(){ // The first identifier was "?" | |
CodeIn = getChar(); // Get another character | |
switch(CodeIn) {// Now lets find what to do with it | |
{ | |
case 'Q'://The second identifier was an "Q" = Manifold pressure | |
warn = ""; | |
warn += getChar(); | |
warn += getChar(); | |
warn += getChar(); | |
warn += getChar(); | |
int warnInt = warn.toInt(); | |
//values below Q12.0 (psi) will give alarm. | |
if(warnInt < 7){warnalarm = 1;} | |
else | |
{warnalarm = 0;} | |
Serial.println("warnalarm"); //for debugging | |
Serial.println(warnalarm); //for debugging | |
break;} | |
{ | |
case 'Y'://The second identifier was an "Y" = Gear position | |
gear = ""; | |
gear += getChar(); | |
gear += getChar(); | |
gear += getChar(); | |
int gearInt = gear.toInt(); | |
//values below Y222 (gear not fully extended) will give alarm. | |
if (gearInt <222) {gearalarm = 1;} | |
else | |
{gearalarm = 0;} | |
Serial.println("gearalarm"); //for debugging | |
Serial.println(gearalarm); //for debugging | |
break; } | |
} | |
if (warnalarm == 1 && gearalarm == 1 && Bvmi!=0) {digitalWrite(2, HIGH);} | |
else{digitalWrite(2, LOW);} | |
} | |
void SLASH(){ // The first identifier was "/" (Annunciators) | |
CodeIn = getChar(); | |
switch(CodeIn) | |
{ | |
case 'N': | |
vac = ""; | |
vac += getChar(); | |
vaci = vac.toInt(); | |
if(vaci > 0 && Bvmi!=0){digitalWrite(5, HIGH);}else{digitalWrite(5, LOW);} | |
break; | |
case 'F': | |
oil = ""; | |
oil += getChar(); | |
oili = oil.toInt(); | |
if (oili > 0 && Bvmi!=0){digitalWrite(6, HIGH);}else{digitalWrite(6, LOW);} | |
break; | |
case 'R': | |
batt = ""; | |
batt += getChar(); | |
batti = batt.toInt(); | |
if (batti > 0 && Bvmi!=0){digitalWrite(4, HIGH);}else{digitalWrite(4, LOW);} | |
break; | |
case 'H': | |
fuel = ""; | |
fuel += getChar(); | |
fueli = fuel.toInt(); | |
if (fueli > 0 && Bvmi!=0){digitalWrite(7, HIGH);}else{digitalWrite(7, LOW);} | |
break; | |
case 'E': | |
stall = ""; | |
stall += getChar(); | |
stalli = stall.toInt(); | |
if (stalli > 0 && Bvmi!=0){digitalWrite(8, HIGH);}else{digitalWrite(8, LOW);} | |
break; | |
} | |
} | |
void INPUTS() | |
{ | |
Kstringnewstate = ""; | |
for (int KpinNo = 10; KpinNo < 12; KpinNo++){ | |
KpinStateSTR = String(digitalRead(KpinNo)); | |
KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 10)); | |
if (KpinStateSTR != KoldpinStateSTR) | |
{ | |
if (KpinNo == 22){if (KpinStateSTR == "1" ){Serial.println ("E42");}else {Serial.println ("E43");}}//Start | |
if (KpinNo == 23){if (KpinStateSTR == "1" ){Serial.println ("C05");}else {Serial.println ("C06");}}//Pitot | |
} | |
Kstringnewstate += KpinStateSTR; | |
} | |
Kstringoldstate = Kstringnewstate; | |
} | |
void PUSHTOTEST(){ | |
int ARRAY_myrecall[8]; //create 8 slots | |
for(int i=2; i<10; i++){ | |
ARRAY_myrecall[i-2] = digitalRead(i); //since i started at 2, subtract 2 (2-2=0) and begin storing in slot 0 of the array. | |
} | |
buttonState = digitalRead(pttButton); | |
if(buttonState==LOW){ | |
for(int i=2; i<10; i++){ | |
digitalWrite(i, HIGH); //light pins 2 thru 9 | |
} | |
return; // prevent blinking of annunc by not allowing the code below to run. | |
} | |
for(int i=2; i<10; i++){ | |
digitalWrite(i, ARRAY_myrecall[i-2]); // recall led state of pins 5 thru 7 prior to button push | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment