Results 1 to 3 of 3
Thread: Autopilot LCD Link2Fs
-
01-03-2018, 06:29 AM #1
- Join Date
- Dec 2017
- Location
- USA
- Posts
- 5
Autopilot LCD Link2Fs
Hello, I've been trying to build a AutoPilot Monitor with link2fs to comunicate to a 16x2 lcd display.
My idea is when NAV button is on it shows "NAV" on the lcd, and when APP is on it shows "APP" in the exact same spot where "NAV" was, and when they are all off, it shows nothing.
I'm using switch cases in the arduino to collect the data:
void EQUAL(){
case 'o' : // receives the state of NAV from Fsx
navon = "";
navon += getChar();
if(navon == "1"){
lcd.setCursor(0, 1);
lcd.print("NAV");
break;
}//end of if
else{
lcd.setCursor(0, 1);
lcd.print(" ");
break;
}//end of else
case 'm': //receives the state of APP from FSX
appon = "";
appon += getChar();
if(appon == "1"){
lcd.setCursor(0, 1);
lcd.print("APP");
break;
}//end of if
else{
lcd.setCursor(0, 1);
lcd.print(" ");
break;
}//end of else
}//end of void equal
After writing this code almost everything is working but when i activate nav and then activate app, it goes blank, what is not happening the other way(i activate app first and then activate nav, works fine)
I would aprecciate if someone could help me!!
-
01-03-2018, 12:47 PM #2
Re: Autopilot LCD Link2Fs
Check the Extractions(x) tab and look to the left of the check box for lines 'o' and 'm'. Can they both show '1' at the same time. You have two inputs, there may be four results, nav off app off, nav off app on, nav on app off, nav on, app on; and a simple either or is not sufficient.
The following will give us four values for the four possible returns - 0 if both switches are off, 1 if nav only is on, 2 if app only is on, and 3 if both switches are on.
- '0' .... A number 0 to 9 when stored as a character has a value 48 higher than its numerical value. eg 0 is 48, 1 is 49 etc. When you subtract the value of char '0' from any single digit returned by getChar(), the result is in the range of 0 to 9.
* 1 or * 2 .... We can apply a 'weight' to each reply by multiplying by an ascending scale. The return for 'o' is 0 or 1. Multiply by 1 the values for navOn are 0 and 1. But, for case 'm', applying a weight of 2 and multiplying the return of getChar() by 2, the result is 0 for off and 2 for on.
Not tested. The principal of (any char - '0') *2; will compile.
global variables
byte navOn = 0; byte appOn = 0; byte switchNavApp;
case 'o' : { // receives the state of NAV from Fsx
navOn = (getChar() - '0') * 1;
switchNavApp = navOn + appOn;
if (switchNavApp == 0) {lcd.setCursor(0, 1); lcd.print(" ");}
if (switchNavApp == 1) {lcd.setCursor(0, 1); lcd.print("NAV");}
if (switchNavApp == 2) {lcd.setCursor(0, 1); lcd.print("APP");}
if (switchNavApp == 3) {lcd.setCursor(0, 1); lcd.print("BOTH ACTIVE");}
}// close case'o'
break;
for case 'm' change navOn = (getChar() - '0') * 1; to appOn = (getChar() - '0') * 2;
OR
char navOn = '0'; char appOn = '0';
case 'o' : { // receives the state of NAV from Fsx
navOn = getChar()
if ((navOn == '0') && (appOn == '0')) {lcd.setCursor(0, 1); lcd.print(" ");}
if ((navOn == '1') && (appOn == '0')) {lcd.setCursor(0, 1); lcd.print("NAV");}
if ((navOn == '0') && (appOn == '1')) {lcd.setCursor(0, 1); lcd.print("APP");}
if ((navOn == '1') && (appOn == '1')) {lcd.setCursor(0, 1); lcd.print("BOTH ACTIVE");}
}// close case'o'
break;
for case 'm' copy the above and change case 'o': to case 'm': then change navOn = getChar(); to appOn = getChar();
Hugh---CYXD ----- TWR --- GND ------ Closed
ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013
-
01-03-2018, 03:24 PM #3
- Join Date
- Dec 2017
- Location
- USA
- Posts
- 5
Re: Autopilot LCD Link2Fs
The Nav And App switch in the autopilot can't be on at the exact same time, so i just removed the value "3" and it worked perfectly.
Thank you so much for all the help, mostly for explaining the code, i'm not a great understander of the arduino coding, so it's always good to learn a few new things!!
Hi is this cpflight card still for sale ? regards Mick
For sale: CPFlight MIP737SE