EAL727Capt
Well-known member
Hello!
Am re-working a sketch which was sent to me and I cannot get it to read/compile correctly.
Background: I am interfacing OEM aircraft radios, gauges, instruments, etc. and have many, many unopened Teensys on my shelf....3.2, 4.1. For the project interface I'm presently working, its the aircraft transponder which radar identifies your aircraft to air traffic controllers.
You'll dial-in a code specified by the controller so he/she may 'see' you on radar.
This code 'coding' on my unit works flawlessly.
I'm having challenges attempting to code the POWER/MODE button. There are three (3) possible modes for my transponder unit:
0 = OFF
1 = STAND-BY
2 = ON
Additionally, the other challenge I'm having is with the IDENT button. When air traffic control requests you to "squawk code 3214 and ident," dialing-in 3214 and activating this button will cause your radar target to blossom momentarily, making it easier for the controller to 'see' and identify you.
There are two (2) conditions:
0 = Off (by default)
1 = Ident
My code, thus far, is as follows:
Compiling error is on the 'else if' section expected '{' before '{' token. Adding or subtracting a { has no effect.
When I remove that portion, it compiles and functions without issue, albeit without the STAND-BY option.
Then second challenge I'm having is with the 'if (digitalRead(9) == HIGH)' section...
It compiles and I'm expecting it to then work in X-Plane, but it doesn't....no interfacing at all with X-Plane for this portion of the sketch. The X-Plane dataref is correct.
I have checked, double-checked and triple-checked every pin connection and they are all correct as is.
I am probably missing something very elementary and simple and will probably hang my head in shame when pointed-out....LOL
Its been baffling to me so after two (2) weeks of constantly working toward a solution, I'm reaching-out to the gurus of the bunch for any insights and guidance.
Thank you in advance.
Jay
Am re-working a sketch which was sent to me and I cannot get it to read/compile correctly.
Background: I am interfacing OEM aircraft radios, gauges, instruments, etc. and have many, many unopened Teensys on my shelf....3.2, 4.1. For the project interface I'm presently working, its the aircraft transponder which radar identifies your aircraft to air traffic controllers.
You'll dial-in a code specified by the controller so he/she may 'see' you on radar.
This code 'coding' on my unit works flawlessly.
I'm having challenges attempting to code the POWER/MODE button. There are three (3) possible modes for my transponder unit:
0 = OFF
1 = STAND-BY
2 = ON
Additionally, the other challenge I'm having is with the IDENT button. When air traffic control requests you to "squawk code 3214 and ident," dialing-in 3214 and activating this button will cause your radar target to blossom momentarily, making it easier for the controller to 'see' and identify you.
There are two (2) conditions:
0 = Off (by default)
1 = Ident
My code, thus far, is as follows:
Code:
//Transponder TEST
const int digit1A = 2; //J1-2 'B' GND ON PIN 8
const int digit1B = 3; //J1-3 'C' GND ON PIN 8
const int digit1C = 4; //J1-4 'D' GND ON PIN 8
const int digit2A = 5; //J1-5 'E' GND ON PIN 8
const int digit2B = 6; //J1-6 'F' GND ON PIN 8
const int digit2C = 7; //J1-7 'G' GND ON PIN 8
const int digit3A = 15; //J1-15 'J' GND ON PIN 8
const int digit3B = 16; //J1-16 'K' GND ON PIN 8
const int digit3C = 17; //J1-17 'L' GND ON PIN 8
const int digit4A = 19; //J1-19 'N' GND ON PIN 8
const int digit4B = 20; //J1-20 'O' GND ON PIN 8
const int digit4C = 8; //J1-28 'P' GND ON PIN 8
const int ident = 9; //J1-14 GND ON PIN 8
const int xpdrON = 1; //J1-23 GND ON PIN 8
FlightSimInteger xpdrCode;
FlightSimInteger xpdrMode;
FlightSimInteger xpdrIdent;
//Function to build the ATC code
int getAtcFreq()
{
int freq = 0;
int digit1 = 0;
int digit2 = 0;
int digit3 = 0;
int digit4 = 0;
bool a1 = !digitalRead(digit1A);
bool b1 = !digitalRead(digit1B);
bool c1 = !digitalRead(digit1C);
digit1 = ((a1 + b1 * 2 + c1 * 4) * 1000);
bool a2 = !digitalRead(digit2A);
bool b2 = !digitalRead(digit2B);
bool c2 = !digitalRead(digit2C);
digit2 = ((a2 + b2 * 2 + c2 * 4) * 100);
bool a3 = !digitalRead(digit3A);
bool b3 = !digitalRead(digit3B);
bool c3 = !digitalRead(digit3C);
digit3 = ((a3 + b3 * 2 + c3 * 4) * 10);
bool a4 = !digitalRead(digit4A);
bool b4 = !digitalRead(digit4B);
bool c4 = !digitalRead(digit4C);
digit4 = (a4 + b4 * 2 + c4 * 4);
freq = (digit1 + digit2 + digit3 + digit4);
return freq;
}
long previousMillis = 0;
long interval = 1000;
void setup()
{
Serial.begin(38400);
pinMode(digit1A, INPUT_PULLUP);
pinMode(digit1B, INPUT_PULLUP);
pinMode(digit1C, INPUT_PULLUP);
pinMode(digit2A, INPUT_PULLUP);
pinMode(digit2B, INPUT_PULLUP);
pinMode(digit2C, INPUT_PULLUP);
pinMode(digit3A, INPUT_PULLUP);
pinMode(digit3B, INPUT_PULLUP);
pinMode(digit3C, INPUT_PULLUP);
pinMode(digit4A, INPUT_PULLUP);
pinMode(digit4B, INPUT_PULLUP);
pinMode(digit4C, INPUT_PULLUP);
pinMode(ident, INPUT_PULLUP);
pinMode(xpdrON, INPUT_PULLUP);
xpdrCode = XPlaneRef("sim/cockpit2/radios/actuators/transponder_code");
xpdrMode = XPlaneRef("FJS/727/Radios/Transponder_ModeKnob");
xpdrIdent = XPlaneRef("sim/cockpit/radios/transponder_id");
}
void loop()
{
FlightSim.update();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
xpdrCode = getAtcFreq();
if (digitalRead(1) == HIGH) {
xpdrMode = 0; // OFF
}
else if {
xpdrMode = 1;} // STBY
else{
xpdrMode = 2;} // ON
}
if (digitalRead(9) == HIGH) {
xpdrIdent = 0; // OFF
}
else {
xpdrIdent = 1; // ON...IDENT
}
}
Compiling error is on the 'else if' section expected '{' before '{' token. Adding or subtracting a { has no effect.
When I remove that portion, it compiles and functions without issue, albeit without the STAND-BY option.
Then second challenge I'm having is with the 'if (digitalRead(9) == HIGH)' section...
It compiles and I'm expecting it to then work in X-Plane, but it doesn't....no interfacing at all with X-Plane for this portion of the sketch. The X-Plane dataref is correct.
I have checked, double-checked and triple-checked every pin connection and they are all correct as is.
I am probably missing something very elementary and simple and will probably hang my head in shame when pointed-out....LOL
Its been baffling to me so after two (2) weeks of constantly working toward a solution, I'm reaching-out to the gurus of the bunch for any insights and guidance.
Thank you in advance.
Jay