Hey guys,
Having a bit of trouble which Ill try and explain the best I can.
I am using a programme called Link2fs which if you are not familiar with it acts as an interface programme between arduino and FSX. Basically it works an input by sending a Serial.println to Link2fs which makes the control in the simulator. From the outputs it read data from FSX and when that data reaches a certain parameter it digitalWrites a pin to activate an LED or an alarm.
My trouble is trying to get multiple switch cases to feed into one LED. So on the aircraft I fly if I drop my manifold pressure below 14inHG whilst my gear is up I get an LED come on. Therefore for that LED to come on two conditions have to be met my Manifold pressure has to drop and my gear has to be up but I have no Idea how to code it. I can get them to work as separate switch cases but not together. Ill post what code I have go so far in the hope that someone can help.
There is lots more on there as it runs my annunciator panel but I am looking at switch case 'Q' & 'Y'
Many thanks
Marc
int AnunPinNo[5] = {2, 3, 4, 5, 6};// the selected pins with LED's
char AnunIdent2[5] = {'E','N','F','H','R'};//Selected items in "Annunciators" in Multi
long AnunButtonStop = 0;
boolean ButtonStopEnable = 0;
int AnunPinValNew[5] = {0,0,0,0,0};//Array for pin values (The new readings)
int AnunPinValOld[5] = {0,0,0,0,0};//Array for pin values (The old readings)
int count = 0; //for array reading
int CodeIn;// Gets the serial read
int bipassSwitchPins = 0; //=1 avoids repetative pin assignments
int dummy;//dummy output until LED's are restored after test
int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button
int KpinNo;
int Koutpin;
String start;
String pitot;
String warn;
int warnalarm;
int gearalarm;
String gear;
String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;
void setup(){
Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
for (int KoutPin = 10; KoutPin < 12; KoutPin++)// Get these pins ready as inputs
{
pinMode(KoutPin, INPUT);
digitalWrite(KoutPin, HIGH);
}
for (count=0;count<7;count++) {// we make all the Anun declarations at once
// Be careful with the above line.(Dont involve a pin that will have a switch on it ,, it can fry your pin or card)
pinMode(AnunPinNo[count], OUTPUT);
digitalWrite(AnunPinNo[count], LOW);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
Serial.begin(115200);
}}
void loop() {
{KEYS();} //Check the "keys" section
{OTHER();}
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 OTHER(){
// Normal "run" stuff in here
}
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();
int pitotInt = pitot.toInt(); // convert it to an integer (Thanks Phill)
if (pitotInt == 1) {digitalWrite(8, HIGH);} else {digitalWrite(8, LOW);}
break;
}
case 'k':{
start = "";
start += getChar();
int startInt = start.toInt();
if (startInt == 1) {digitalWrite(9, HIGH);} else {digitalWrite(9, 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();
int warnInt = warn.toInt();
if (warnInt <6.3) {warnalarm = 1;}else{warnalarm = 0;}
break;
}
case 'Y':{//The second identifier was an "Y" = Gear position
gear = "";
gear += getChar();
gear += getChar();
gear += getChar();
int gearInt = gear.toInt();
if (gearInt <2) {gearalarm = 1;}else{gearalarm = 0;}
break;
}
if (warnalarm ==1 && gearalarm == 1) {digitalWrite(7, HIGH);}else {digitalWrite(7, LOW);}
}
}
void SLASH(){ // The first identifier was "/" (Annunciators)
CodeIn = getChar();
for (count=0;count<7;count++) {
if (CodeIn == AnunIdent2[count]){
AnunPinValNew[count] = (getChar()- 48);
if (AnunPinValNew[count] == 1){
if (AnunPinValOld[count] < 1) {digitalWrite(AnunPinNo[count], HIGH);
AnunPinValOld[count] = AnunPinValNew[count];}}
if (AnunPinValNew[count] == 0){
if (AnunPinValOld[count] > 0) {digitalWrite(AnunPinNo[count], LOW);AnunPinValOld[count] = AnunPinValNew[count];
}
}
}
}
}
void KEYS()
{
Kstringnewstate = "";
for (int KpinNo = 10; KpinNo < 12; KpinNo++){
KpinStateSTR = String(digitalRead(KpinNo));
KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 10));
if (KpinStateSTR != KoldpinStateSTR)
{
if (KpinNo == 10){if (KpinStateSTR == "1" ){Serial.println ("E42");}else {Serial.println ("E43");}}//Start
if (KpinNo == 11){if (KpinStateSTR == "1" ){Serial.println ("C05");}else {Serial.println ("C06");}}//Pitot
}
Kstringnewstate += KpinStateSTR;
}
Kstringoldstate = Kstringnewstate;
}