PDA

View Full Version : Arduino input & output



BuzziBi
04-24-2013, 07:28 AM
I need help to split the input and output on the arduino mega! It was easy on the Uno card because the options were fewer.Now with a mega card I found it difficult :D

Using Jim's pde it list ie like this:

Quadrature quad1(8, 9); //added .. the RE is connected to pins 8 and 9
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup()

for (int doutPin = 10; doutPin <= 19; doutPin++) //added.. changed the 8 to a 10,, no need to set it up for "keys" but we still need pin 10 setup as a digital pin.
void loop() {

for (int pinNo = 11; pinNo <= 19; pinNo++){ //added... changed the 8 to a 11 to stop "keys" reading the pins as well.
pinStateSTR = String(digitalRead(pinNo));


oldpinStateSTR = String(stringoldstate.charAt(pinNo - 11)); //added.. changed the 8 to 11 to keep pins string inactive for pins 8 and 9 and 10




I will have a setup like this:
Quadrature quad1(9, 10); //added .. the Heading RE is connected to pins 9 and 10
Quadrature quad2(11, 12); //added .. the Altitude RE is connected to pins 11 and 12
Quadrature quad3(13, 14); //added .. the QNH RE is connected to pins 13 and 14
Lets say I dont wont to use 15 to 21 for now, but maby for future RE's
LCD on:
LiquidCrystal lcd1(8, 6, 5, 4, 3, 2);
LiquidCrystal lcd2(8, 7, 5, 4, 3, 2);
Pushbuttons from input 22 to 41
LED's on output 42 to 53

void setup()
How do I now change this line?
for (int doutPin = 10; doutPin <= 19; doutPin++) //added.. changed the 8 to a 10,, no need to set it up for "keys" but we still need pin 10 setup as a digital pin.

void loop() {
And this line?
for (int pinNo = 11; pinNo <= 19; pinNo++){ //added... changed the 8 to a 11 to stop "keys" reading the pins as well.
pinStateSTR = String(digitalRead(pinNo));
oldpinStateSTR = String(stringoldstate.charAt(pinNo - 11)); //added.. changed the 8 to 11 to keep pins string inactive for pins 8 and 9 and 10

BuzziBi
04-25-2013, 01:58 PM
One question in this context.
Is there a difference, where in the "loop" I configures the various buttons and Led's
I've been sitting for several days with this problem.
I've got buttons to work, I have LED's to work, but in combination, I have failed.
When I modified Jim's. "pde_inout_v4" I did'nt get it to work.
But today I started with the starter2.pde and now it works!
The only difference I can see is that the Buttons read is at the start of the loop in the starter2.pde
but at the end in the pde_inout_v4.
Or can it simply be that I have made an error I could'nt see? :D
But seriously. I have occasionally pondered whether there is a difference!

JMeller
04-26-2013, 12:09 AM
It doesn't matter. What matters is what happens to the variable until it is assigned a new value.

BuzziBi
04-28-2013, 05:21 PM
Stuck again! :oops:
Need help to solve this!
If I use the keys in pde_inout_v4, and I want to print a line on the display (LCD 16x2)
every time the button (pinNo) 12 is LOW


Let's say I want to print "STANDBY" on
lcd.setCursor (8, 1); every time the button (pinNo) 12 is LOW

I understand that Link2fs reads the button like: D121 or D120.

So if the pinNo is 120, I would like to print "STANDBY" on the LCD 16x2, on cursor 8, line 1

Suggestions?



// Now the bit for the "keys" input stringnewstate = "";
for (int pinNo = 8; pinNo <= 19; pinNo++){
pinStateSTR = String(digitalRead(pinNo));


oldpinStateSTR = String(stringoldstate.charAt(pinNo - 8));

if (pinStateSTR != oldpinStateSTR)
{
Serial.print ("D");
if (pinNo < 10) Serial.print ("0");
Serial.print (pinNo);
Serial.print (pinStateSTR);
delay(11);
}
stringnewstate += pinStateSTR;
}

stringoldstate = stringnewstate;
delay(11);
}

JMeller
04-29-2013, 07:30 AM
Does this help?

if (pinNo == 12){
if (pinStateSTR == "0"){
lcd.setCursor(8,1);
lcd.print ("STANDBY");
}else{
l//cd.setCursor(8,1);
// lcd.print ("ACTIVE");

}
}

BuzziBi
04-29-2013, 11:57 AM
Does this help?

if (pinNo == 12){


Unfortunately JMeller,
I did not succeed with that one either. :(
I wonder if you have to use something like:


if ((pinNo == 12) && (pinStateSTR == "0"))(
then do action.......

But I can not get it to work :evil:

JMeller
04-29-2013, 07:32 PM
Hmmm. If you placed the code between the following brackets, there is not a reason it should not have worked... especially if it is sending the keystroke command to Link2FS.

if (pinStateSTR != oldpinStateSTR)
{
Serial.print ("D");
// place code somewhere in here
}



Do you have an LCD.clear() erasing it and then rewriting the lcd with other data?

And, yes, you could use - if (pinNo == 12 && pinStateSTR == "0"){ // do something} either approach works the same.

However, if you are not using "else"and you have a piece of code written after the - if (pinNo == 12 && pinStateSTR == "0"){ // do something} - to write onto the lcd in the same spot (8,1), it will overwrite the STANDBY text you had just told it to write. And since pinNo will equal 19 after it leaves the for-next loop, you cannot use - if (pinNo == 12 && pinStateSTR == "1"){ // do something} later in the void loop().

I'm sure I covered things you already knew, but I wanted to cover the whole gamut for the readers.

BuzziBi
05-01-2013, 10:35 AM
Here comes the news .... I suppose you've already guessed it, I'm still working With the Transponder :)
I have removed the "key,s bit from the starter pde", This one.
// Setup the pins as inputs as used by "Keys" (For the "Keys" program avoid actually using Pin 13 as an input ,, long story)
for (int doutPin = 8; doutPin <= 19; doutPin++) // if you have a Mega card and want to use all the pins ,, change the 19 to 69
{
pinMode(doutPin, INPUT);
digitalWrite(doutPin, HIGH);
} And now set up the buttons one by one. The Rotary Switch "Mode Selector" on the 47,48,49 and 50 pin. Here is the code If anyone is interested.

// This constant won't change:
const int buttonSBY = 47; // the Rotary Switch pin
const int buttonTST = 48; // the Rotary Switch pin
const int buttonON = 49; // the Rotary Switch pin
const int buttonALT = 50; // the Rotary Switch pin
// Variables will change:
int buttonState1 = 0; // current state of the SBY Rotary Switch
int lastButtonState1 = 0; // previous state of the SBY Rotary Switch
int buttonState2 = 0; // current state of the TST Rotary Switch
int lastButtonState2 = 0; // previous state of the TST Rotary Switch
int buttonState3 = 0; // current state of the ON Rotary Switch
int lastButtonState3 = 0; // previous state of the ON Rotary Switch
int buttonState4 = 0; // current state of the ALT Rotary Switch
int lastButtonState4 = 0; // previous state of the ALT Rotary Switch
int xx;
int pinState;
int pinNo;
int doutpin;
int j1;
int j2;
#include <liquidcrystal.h>
LiquidCrystal lcd1(8, 6, 5, 4, 3, 2);
LiquidCrystal lcd2(8, 7, 5, 4, 3, 2);
String altit, altitold, apHeading, apHeadingold, Transponder, Transponderold; // String for Buttons
// The QNH must be given a Key an made funcsionable via FSUIPC "Kohlsman"
String gearnose, gearnoseold, gearL, gearLold, gearR, gearRold, flaps, flapsold, AP, APold; //Strings for LED's
String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate; //String for read states

void setup() {

// initialize the Rotary Switch pins as a input:
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
//########## Initialize serial communication:
Serial.begin(115200);
//########## set up the 1.LCD's number of columns and rows:
lcd1.begin(16, 2);
// Print a message to the LCD.
lcd1.setCursor(0, 0);
delay (11);
lcd1.print("");
delay (11);
lcd1.setCursor(0, 1);
delay (11);
lcd1.print("");
delay (11);
//########## set up the 2.LCD's number of columns and rows:
lcd2.begin(16, 2);
// Print a message to the LCD.
delay (11);
lcd2.print("");
delay (11);
lcd2.setCursor(0, 1);
delay (11);
lcd2.print("");
delay (11);

Serial.flush();
}
void loop() {

//###Rotary Switch Read ######
buttonState1 = digitalRead(buttonSBY);
buttonState2 = digitalRead(buttonTST);
buttonState3 = digitalRead(buttonON);
buttonState4 = digitalRead(buttonALT);
//### SBY Button
if (buttonState1 != lastButtonState1) {
if (buttonState1 == HIGH) {
{
lcd2.setCursor(5,1);
delay (11);
lcd2.print("SBY");}
}
else {
{lcd2.clear();
}
}
lastButtonState1 = buttonState1;
}
//### TST Button
if (buttonState2 != lastButtonState2) {
if (buttonState2 == HIGH) {
{
lcd2.setCursor(5,1);
delay (11);
lcd2.print("TST");}
}
else {
{lcd2.clear();
}
}
lastButtonState2 = buttonState2;
}
//### ON Button
if (buttonState3 != lastButtonState3) {
if (buttonState3 == HIGH) {
{
lcd2.setCursor(5,1);
delay (11);
lcd2.print("ON");}
}
else {
{lcd2.clear();
}
}
lastButtonState3 = buttonState3;
}
//### ALT Button
if (buttonState4 != lastButtonState4) {
if (buttonState4 == HIGH) {
{
lcd2.setCursor(5,1);
delay (11);
lcd2.print("ALT");}
}
else {
{lcd2.clear();
}
}
lastButtonState4 = buttonState4;
}
//### End of Rotary Switch Read ######
}
It looks like the solution on the LCD print line was this.
//### SBY Button
if (buttonState1 != lastButtonState1) {
if (buttonState1 == HIGH) {
{
lcd2.setCursor(5,1);
delay (11);
lcd2.print("SBY");}
}
else {
{lcd2.clear();
} What I do not understand, is that even though I have resistor between input and Ground, I have to use the (buttonstate == HIGH) in the code. Setting only "output" in void setup and "HIGH" in void loop, if not, it caused the lcd to pring while disconnected and remove print while Connected??? Still a newbie, I could not get your suggestion to work inside the "keys" code. I must admit, that you were right in your suspicions :oops:. The first attempts min code was outside. I'm still confused by "()" and "{}" :roll: Anyway, we have progress ....
As it is now, so I set SQUAWK code with a arduino one modifyed to act as a usb keyborad, And using a mega card to deal with RE's, Buttons and Lcd's. It still remains to put everything together, but any case, now things are starting to function independently. </liquidcrystal.h>

JMeller
05-01-2013, 06:32 PM
Good to see you got it going, Roy.


I studied your code. During which, I found excessive use of { & }. I'm not critisizing - I started out doing the same ... heck, we all did. So, in order to get you up and running faster than I did, I took the liberty to modify the code - your code - so you can easily pick out what is going on.


Firstly, I declared three extra variables at the top - a string and 2 arrays; also deleted the oldbuttonState variables.

Secondly, I deleted all of the delays in the lcd print; unless your specific chip needs them, they are not necessary.

Third, I used the arrays to store the button states - newRead near the top of void loop(); oldRead at the bottom of void loop().

Fourth, I compare the newRead array to the oldRead array to determine if an lcd2 clear is needed.

Fifth, I removed as many {} that were not necessary and then positioned the lines of code to be easily followed at a glance. This method may not be for you, but I throw there it out as a possible alternative; Personally, I prefer this form - it allows me to easily scan down the code.

Sixth, I created another loop called "LCD2print()". This allows you to place lengthy code which gets in the way of reading & comprehension out of site. Simply type "LCD2print();" in your code when you want that loop to be fetched. This also allows code which is frequently used to be fetched instead of being re-written all of the time.


#include LiquidCrystal.h (webpage removed greater-than & less-than signs)<liquidcrystal.h><liquidcrystal.h><liquidcrystal.h>
// This constant won't change:
const int buttonSBY = 47; // the pin that the pushbutton is attached to
const int buttonTST = 48; // the pin that the pushbutton is attached to
const int buttonON = 49; // the pin that the pushbutton is attached to
const int buttonALT = 50; // the pin that the pushbutton is attached to
// Variables will change:
int buttonState1 = 0; // current state of the SBYbutton
int buttonState2 = 0; // current state of the TSTbutton
int buttonState3 = 0; // current state of the ONbutton
int buttonState4 = 0; // current state of the ALTbutton
int xx;
int pinState;
int pinNo;
int doutpin;
int j1;
int j2;


LiquidCrystal lcd1(8, 6, 5, 4, 3, 2);
LiquidCrystal lcd2(8, 7, 5, 4, 3, 2);


// ++++ JM ADDED
String SWstate; // used as Switch placement LCD text
int newRead [4]; // declare newRead as an array w/ 4 slots
int oldRead [4]; // declare oldRead as an array w/ 4 slots
// +++++++++++


String altit, altitold, apHeading, apHeadingold, Transponder, Transponderold; // String for Buttons
// The QNH must be given a Key an made funcsionable via FSUIPC "Kohlsman"
String gearnose, gearnoseold, gearL, gearLold, gearR, gearRold, flaps, flapsold, AP, APold; //Strings for LED's
String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate; //String for read states


void setup() {

for (int doutPin = 54; doutPin <= 69; doutPin++)
{
pinMode(doutPin, OUTPUT);
digitalWrite(doutPin, LOW);
}
stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
//########## Setup the pins 21 to 25 as inputs for the REButtons
for (int doutPin = 21; doutPin <= 25; doutPin++)
{
pinMode(doutPin, INPUT);
digitalWrite(doutPin, HIGH);
}
// initialize the button pin as a input:
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
//########## Initialize serial communication:
Serial.begin(115200);
//########## set up the 1.LCD's number of columns and rows:
lcd1.begin(16, 2);
// Print a message to the LCD.
lcd1.setCursor(0, 0);
lcd1.print("");
lcd1.setCursor(0, 1);
lcd1.print("");

//########## set up the 2.LCD's number of columns and rows:
lcd2.begin(16, 2);
// Print a message to the LCD.
lcd2.print("");
lcd2.setCursor(0, 1);
lcd2.print("");

Serial.flush();
}


void loop() {
//###Rotary Switch Read ######
buttonState1 = digitalRead(buttonSBY);
buttonState2 = digitalRead(buttonTST);
buttonState3 = digitalRead(buttonON);
buttonState4 = digitalRead(buttonALT);

newRead [0] = buttonState1; // Store in newRead slot0
newRead [1] = buttonState2; // Store in newRead slot1
newRead [2] = buttonState3; // Store in newRead slot2
newRead [3] = buttonState4; // Store in newRead slot3

// Compare array slots to determine if LCD clear is needed
for (int arrayNUM = 0; arrayNUM <= 3; arrayNUM++) { // 0 based - 4 slots
if (newRead [arrayNUM] != oldRead [arrayNUM]) //compare slot #s and clear LCD if needed
{lcd2.clear(); break;}
}

//### SBY Button
if (newRead [0] != oldRead [0] && buttonState1 == HIGH)
{SWstate = "SBY"; LCD2print();}


//### TST Button
if (newRead [1] != oldRead [1] && buttonState2 == HIGH)
{SWstate = "TST"; LCD2print();}


//### ON Button
if (newRead [2] != oldRead [2] && buttonState3 == HIGH)
{SWstate = "ON"; LCD2print();}


//### ALT Button
if (newRead [3] != oldRead [3] && buttonState4 == HIGH)
{SWstate = "ALT"; LCD2print();}

oldRead [0] = buttonState1; // Store in oldRead slot0
oldRead [1] = buttonState2; // Store in oldRead slot1
oldRead [2] = buttonState3; // Store in oldRead slot2
oldRead [3] = buttonState4; // Store in oldRead slot3
//### End of Rotary Switch Read ######
} // End void loop

void LCD2print(){
lcd2.setCursor(5,1);
lcd2.print(SWstate);
} // End LCD2print


Hope you found some of this to be beneficial.


As for the input, ground, and the lcd - you may have to go into a bit more detail; I could not quite understand.</liquidcrystal.h></liquidcrystal.h></liquidcrystal.h>

BuzziBi
05-02-2013, 05:06 AM
Thank JMeller.
It was a much cleaner way to set it all up!
I have to let it sink in a bit, and try and understand what is happening.
It's a completely different way of doing it, but I might be able to understand it after some studying.
The code works any case!
The strange thing about this, is that I become more addicted on the way. Thinking coding all the time
What I meant by the "input, ground, and lcd, was: I did set the input (47 to 50) "HIGH" with a resistor.
Normally you mention this in the "void setup" If I did that, it did not work.
Still asking if the input is "HIGH" or "LOW" in the "void loop" it now Works? Strange?

Jim NZ
05-02-2013, 06:53 AM
Roy ,, I've been watching you and James with this problem and that add-on is really making you jump thru hoops to get things to work.

I have a wee play tonight and it will make life a lot easier if it works,,, download this and put it into the same folder as the "InOut exe" ,, then run it.

(Link removed ,, see later posts)

What it has is a very big rework of the "keys" section and I threw in direct simconnect injection for the transponder code ,, which means (if it works) that your code can be a lot simpler ,, but it depends on how your add-on is handling the transponder codes.

There is a button to change the codes and if the button works ,,, then you can send from the Arduino a transponder code in the format of ,,,
W1234
and it will change the transponder code to 1234 or what ever you want. It must be preceded with a capital W.

Its a quick hack as it may not work with your add-on as I said.
Hopefully I haven't bust anything that was working before the hack.
(It's not a finished program ,,, just a rough untidy hack to see if it will work)

Lets Know ,,,, Jim

JMeller
05-02-2013, 08:34 AM
Roy,
Ha! I can totally relate to the coding addiction!

Anyway, about setting the Input HIGH - as stated in a previous thread, I've never set it HIGH. I'm unsure of your level of electronics so I'm going to run through the basics pertaining to this subject - if nothing else for the new arduino participants reading your thread.

A typical setup is to have all inputs low and do something when HIGH. To prevent erratic behavior from an input floating HIGH, EACH input requires a "pull-down" resistor; I use 10K from gnd to each input. To make the input HIGH, I use a value of 10K or less (since I am using a 10K "pull-down") to +5vdc for each input to override the pull-down resistor current. None of the resistors are shared with another input in this single push-button scenario.

In a case where I am using a rotary switch, each input has the pull-down resistor to gnd. The center "pole" has an inline (series) resistor of a value less than my pull down resistor to +5vdc. In this scenario, the center pole resistor (pull-up) is the only resistor shared between inputs because it will never be pulling up more than one input at a time as I rotate the switch.

So, to summarize, the only thing one must do in their code is to declare the specific pins as Inputs - no need to write them HIGH (or LOW) ; the resistors control whether it is HIGH or LOW.

You may have had it wired as such - but this would't explain the erratic behavior you were experiencing.


@Jim - Nice add to Link2FS! That should makes sending xpdr codes to FSX a breeze.

BuzziBi
05-02-2013, 11:28 AM
Thanks for wanting to help Jim NZ. :D
Without that I know what the new part of the program does, what it sends to FSX, I am unable to understand WHAT to program!
I tried to serie.print a W and a pin number, ("W22") just to see what happens. Started the program and got this:

7784 Surely as deserve'ed :p
Maybe a little more help here so I may know what to do!
EDIT: Tried the program on a Laptop without the FSX, (Have not tried it on the SimComputer though) and did not get the Runtime error this time. (I really need to stop using the other lap top :roll: ) Still I see no other use of the New program part, other than it sends the keystroke to the New part.
Is it to understand like this: if I press a button on the arduino, it appears in the W section, now I enter the "Set Transponder" and a code that is stored in simconnect as a command? As I don't understand it, I'm just throwing questions into the air :)

@ JMeller: You wondered if I had knowledge of electronics. In fact, I have a big A in digital electronics. You no the zero, one, or, nor and so on. Got it 17 years ago. Have not used it since then. But I guess you realize'ed that after reading what I'm writeing :mrgreen:
I can at least brag about it :mrgreen:

JMeller
05-02-2013, 01:34 PM
My guess as to why you received the error -
When you are sending "W", his program is looking for EXACTLY four characters to follow - no more and no less; and, specifically numbers.

Therefore, if you want to set the xpdr code to 4253, you will Serial.print ("W4253").

BuzziBi
05-02-2013, 01:48 PM
OK. But so....... What happends with the "W4353"?

JMeller
05-02-2013, 01:56 PM
His program trims off the "W" and then shoves 4253 directly into SimConnect (FSX). You'll then see your xpdr numbers (4253) reflected on your radio stack inside the sim. Piece of cake.

BuzziBi
05-02-2013, 01:58 PM
I had a suspicion that it was so ;)
But what about FSX and focus on the radio stack?

JMeller
05-02-2013, 02:04 PM
I think this where you are confusing keyboard emulating and SimConnect. With SimConnect and Link2FS, data can be sent from the arduino to Link2FS, which then hurls the data into SimConnect. This happens even with FSX minimized so I can type this response. However, as you know, keyboard emulators require focus on the intended application running.

BuzziBi
05-02-2013, 06:39 PM
Ok. A little brain storming?
Lets say that ATC gives me the squawk code 2436.
I now have to set the code with my 0 to 7 buttons on my transponder.
I push the 2, the 4, the 3 and the 6 button.
To set this up in the sketch,
when pushing the 2 button, serialprint W2
when pushing the 4 button, seroalprint W4 and so on with all 4 digits?
The Link2fs vill no send this data in to SimConnect who on its side know that this data is for the XPNDR?

I cant program progam serialprint "2436" on one button, because I dont know what code the ATC will give me!

Unless Jim has found a way to owerride FSX built in way to hadle the XPNDR settings with DEC/INC the one, ten, hundred and tousand digits, I cant understand how this works.

Only other way I know off, is the use of offset treatment.

JMeller
05-02-2013, 08:06 PM
You're on the right track. You cannot send "W2", "W4", etc. It has to be "W2436".
To accomplish this, it is assumed the only time you press 0-7 is to set a new xpdr code.

Therefore, in your sketch, you will need the first button pressed to initiate a:
1.) start sequence = True
2.) a time-out of the xpdr entry


When a subsequent button is pressed, it:
1.) restarts the time-out entry
2.) knows how many buttons you have pressed thus far

At the 4th button press, it will:
1.) call for the command to Serial.print ("Wnnnn")

At anytime it takes too long to push the next number, start sequence = false.


Hints:
if (anyButton == HIGH) {start_sequence = True; LoopCycle = 0;}

If (LoopCycle = 5000){start_sequence = False; xpdrCode = "";}

xpdrCode += bPress_string; // build the transponder code number string

LoopCycle = LoopCycle + 1 // used to count how many times the code has looped (start to finish) since the last button press.

if (xpdrCode.Length == 4){start_sequence = False; LinkFS_send();}



void LinkFS_send(){
xpdrCode = "W" + xpdrCode
Serial.print (xpdrCode)
xpdrCode = ""
}


Hope this points you in the right direction.
[edit] Cleaned up hints section.
Also, Jim already has the inc/dec functions built into Link2FS via keys section. What he has done, specifically for you, is to create an easy path to send the entire xpdr code via one print line of code. Pretty cool stuff, really! It means less coding - for us anyway! :)

BuzziBi
05-03-2013, 05:59 AM
Having studied your suggestions for code (a a couple of hours now) JMeller.
I'm afraid this programming is faaaaaaaaaaaar above my head. :(
I have not reached this stage in the learning process yet.
What does it take to get you to write the code? A virtual hug ;)
That's a lot of readers here! Maybe others feels to contribute?


It is surely many more than me who could imagine this feature in conjunction with Link2fs.
I've spent so many hours on Googling xpndr.
Prefabricated modules, which destroys half of you're account and all off the fun, there are, indeed there are. (as surely as if it were Joda from Star Wars who wrote that sentence)
(Have noticed that if you google FSX DIY Cockpit, theis brings up a lot of Youtube videos with people who have bought EVERYTHING. The only DIY they had contributed are, Plug and Play! Still they call it DIY. Shame on them :mad:


With the exception of the arduino keyboardhack in conjunction with other software, I have not found anything that can be used on the Arduino. Alternatively, I continue in this direction.
So right now, I have capitulated!

I'm afraid that, if I'm going to try and fail until something makes sense, I'm going to be pain in the *** (excuse the language) on this forum :roll:

JMeller
05-03-2013, 12:04 PM
Roy,
You can do this... you're selling yourself short. Don't worry about trying, failing and asking questions. It pains me more to think you would rather use a keyboard emulator rather than use the powerhouse you already have.


I whipped up some quick mods in your code:
I inserted all of the hints from the previous post; I also added a debounce to the pushbutton/rotary switch for safe measure.


The result can be viewed using the serial monitor in the arduino programmer. DO NOT connect to Link2FS - this will not allow you to utilize the serial monitor. After you study the serial monitor, feel free to close it; then you can connect to Link2FS. So long as the diagnostic print lines do not interfere, it should pass "Wnnnn" to Link2FS with no problem.


I used your xpdr rotary switch as a substitute for push buttons 0-3; Simply watch the serial monitor for creating the xpdr string. I tested it - you shouldn't have any issues.


<liquidcrystal.h>#include LiquidCrystal.h //(webpage removed greater-than & less-than signs)// This constant won't change:
const int buttonSBY = 47; // the pin that the pushbutton is attached to
const int buttonTST = 48; // the pin that the pushbutton is attached to
const int buttonON = 49; // the pin that the pushbutton is attached to
const int buttonALT = 50; // the pin that the pushbutton is attached to
// Variables will change:
int buttonState1 = 0; // current state of the SBYbutton
int buttonState2 = 0; // current state of the TSTbutton
int buttonState3 = 0; // current state of the ONbutton
int buttonState4 = 0; // current state of the ALTbutton
int xx;
int pinState;
int pinNo;
int doutpin;
int j1;
int j2;




LiquidCrystal lcd1(8, 6, 5, 4, 3, 2);
LiquidCrystal lcd2(8, 7, 5, 4, 3, 2);




// ++++ JM ADDED
String SWstate; // used as Switch placement LCD text
int newRead [4]; // declare newRead as an array w/ 4 slots
int oldRead [4]; // declare oldRead as an array w/ 4 slots
boolean start;
long LoopCycle = 75000;
long debounce;
// +++++++++++




String altit, altitold, apHeading, apHeadingold, Transponder, Transponderold; // String for Buttons
// The QNH must be given a Key an made funcsionable via FSUIPC "Kohlsman"
String gearnose, gearnoseold, gearL, gearLold, gearR, gearRold, flaps, flapsold, AP, APold; //Strings for LED's
String oldpinStateSTR, pinStateSTR, stringnewstate,stringoldstate; //String for read states




void setup() {

for (int doutPin = 54; doutPin <= 69; doutPin++)
{
pinMode(doutPin, OUTPUT);
digitalWrite(doutPin, LOW);
}
stringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
//########## Setup the pins 21 to 25 as inputs for the REButtons
for (int doutPin = 21; doutPin <= 25; doutPin++)
{
pinMode(doutPin, INPUT);
digitalWrite(doutPin, HIGH);
}
// initialize the button pin as a input:
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
//########## Initialize serial communication:
Serial.begin(115200);
//########## set up the 1.LCD's number of columns and rows:
lcd1.begin(16, 2);
// Print a message to the LCD.
lcd1.setCursor(0, 0);
lcd1.print("");
lcd1.setCursor(0, 1);
lcd1.print("");

//########## set up the 2.LCD's number of columns and rows:
lcd2.begin(16, 2);
// Print a message to the LCD.
lcd2.print("");
lcd2.setCursor(0, 1);
lcd2.print("");

Serial.flush();
}




void loop() {
//###Rotary Switch Read ######
buttonState1 = digitalRead(buttonSBY);
buttonState2 = digitalRead(buttonTST);
buttonState3 = digitalRead(buttonON);
buttonState4 = digitalRead(buttonALT);


// check to see if user takes too long
if (LoopCycle == 75000){start = false; SWstate = ""; lcd2.clear(); Serial.println("TIME-OUT - ");LoopCycle = 75001;}


if(debounce == 1000){ //debounce rotary/push switch
newRead [0] = buttonState1; // Store in newRead slot0
newRead [1] = buttonState2; // Store in newRead slot1
newRead [2] = buttonState3; // Store in newRead slot2
newRead [3] = buttonState4; // Store in newRead slot3


// Compare array slots to determine if LCD clear is needed
for (int arrayNUM = 0; arrayNUM <= 3; arrayNUM++) { // 0 based - 4 slots
if (newRead [arrayNUM] != oldRead [arrayNUM] ) //compare slot #s and clear LCD if needed
{ start = true; LoopCycle = 0; debounce = 0;}//lcd2.clear(); break;}
} // END for-next
} // END debounce of switch




if (start == true){
//### SBY Button
if (newRead [0] != oldRead [0] && buttonState1 == HIGH )
{SWstate += "0"; LCD2print();}




//### TST Button
if (newRead [1] != oldRead [1] && buttonState2 == HIGH )
{SWstate += "1"; LCD2print();}




//### ON Button
if (newRead [2] != oldRead [2] && buttonState3 == HIGH )
{SWstate += "2"; LCD2print();}




//### ALT Button
if (newRead [3] != oldRead [3] && buttonState4 == HIGH )
{SWstate += "3"; LCD2print();}

// Check to see if SWstate contains 4 characters
if (SWstate.length() == 4){start = false; LinkFS_send();}


// Increase Time-out timer
LoopCycle = LoopCycle + 1;


} // END if (start == true)


debounce = debounce + 1; if (debounce == 2000){debounce =0;}
oldRead [0] = newRead [0]; // Store in oldRead slot0
oldRead [1] = newRead [1]; // Store in oldRead slot1
oldRead [2] = newRead [2]; // Store in oldRead slot2
oldRead [3] = newRead [3]; // Store in oldRead slot3
//### End of Rotary Switch Read ######


} // End void loop


void LCD2print(){
lcd2.setCursor(5,1);
lcd2.print(SWstate);
Serial.println ("ENTRY - " + SWstate);
} // End LCD2print


void LinkFS_send(){
SWstate = "W" + SWstate;
Serial.println (SWstate);
SWstate = "";
} // END LinkFS_send



Have a good study.. & good luck!</liquidcrystal.h>

BuzziBi
05-03-2013, 02:59 PM
Thanks JMeller! You're the man :cool:
I did not really believe that you'ld let me off that cheap! :)
I am looking forward to test code, not tonight. I have promised my partner corn cobs tonight, so I'll be going to the kitchen and keep that promise. At the same time, I'm setting up an old lap top that I found at recycling market today. My father in law needs new. I will let you know thogh!
Cant wait until tomorrow, I'm probably dreaming codes tonight. Thanks for putting up with my ignorance.

By the way, do you know what this is?Arduino Playground - Eclipse (http://playground.arduino.cc/code/eclipse)

Jim NZ
05-04-2013, 06:18 AM
Roy that hacked "inOut" trial program had a bug in it which would only show up after a certain sequence of events.
It would stop receiving from the card which can make programming a nightmare.

You can download a fixed one here.
Link removed (Too old now)


Same thing ,, just put it into the same folder as the older "inOut" program. (It need the other files to run)


Have fun ,,, Jim

BuzziBi
05-04-2013, 12:16 PM
TX Jim.
I'm looking forward to trying it. This day went down the drain. But tomorrow, tomorrow :p

BuzziBi
05-06-2013, 11:46 AM
I still get the Run-time error 13, type mismatch. Jim.
I Now run the program from link2fs_inout_v4 folder, on my FSX game computer !
Even with JMeller's test code I get the same run-time error :(
It looks like it works until I press "Connect to Com Port, then comes the error message.

Jim NZ
05-07-2013, 12:28 AM
OK ,, I presume that you can see the extractions from FSX before you hit connect.

A couple of things to try ,,,

Delete the file called "INOUTv1e.ini" ,, then open "Link2fs_inout" and try connecting again.
This will erase all your ticked settings so you will have to tick them again and save.

If that don't work ,, then ,,

Delete all my stuff from all directories that you put my files into.(you can leave the Zip file)
Delete the (now empty) folders.
Make a folder ,, name it anything you like as long as it's different to what you previously used.
Extract all my stuff into it.
Double click on the "reg" file that suits your operating system.

Basically follow exactly all the instructions that came with my program.
Don't put any files anywhere else.

In case you strike this bug that's just come to light ,, where the com.s from the Arduino wont work ,, do the following ,,,

Have the Arduino plugged into the USB and running ,,,,
Start "InOut" and connect to it.
Press the reset button on the Arduino.
It will start working.

This bug is fixed in the next update. (Soon)

It should work ,,, lets know.

Cheers ,,, Jim

EDIT ,,, I had the reboot sequence wrong ,, corrected now.

BuzziBi
05-07-2013, 05:44 AM
Hey Jim!
O joy, it Works.
I first tried to delete just the .Ini file, but NO GO.
So I deleted everything that had to do with Link2fs, folders, files and registry entries.
The excitement was great when I hooked up. Success!
Now I nead to put together the code again. I have destroyed it completely in all experiments. Coming back with the result.
If I get everything working, would you or JMeller look through the code before publishing it. I can email it to you.

Jim NZ
05-07-2013, 06:28 AM
Great you got it working Roy ,,, I been playing around here doing the main program update and it goes fine in the compiler BUT ,, on heavy testing I got a "Run time error 13" when it was run by itself ,, but now I think I have it sorted.
So ,, until you get another update (the main program) you may still get that error sometimes.

Re your Arduino code ,, to be quite honest James (JMeller) is away ahead of me with that sort of thing so post your code at any rate and we'll sort it out hopefully.

Posting your code (even if it's wrong) can help other people with learning "bits and pieces".

Stay tuned ,, The update is close ,,, Jim

BuzziBi
05-07-2013, 06:06 PM
Here comes the first attempt at Sketch to Squawk Transponder.
JMeller,
I was unable not built the two proposed code you created together, But it works!
It can certainly discuss how the LCD should display the different "Mode's", all suggestions are interesting.
I got a lot of extra work when it turned out that the Rotary Switch I used did not work as expected. It overlapped points of contact so that two outputs were connected to the center pin simultaneously :(

Take a look at the result:
http://www.youtube.com/watch?v=w1Sp6CZtjFs&feature=youtu.be



// This constant won't change:const int buttonOFF = 46; // the pin that the Rotary Switch is attached to.
const int buttonSBY = 47; // the pin that the Rotary Switch is attached to.
const int buttonTST = 48; // the pin that the Rotary Switch is attached to.
const int buttonON = 49; // the pin that the Rotary Switch is attached to.
const int buttonALT = 50; // the pin that the Rotary Switch is attached to.
const int buttonZero = 51; // the pin that the #Zero Button is attached to.
const int buttonOne = 52; // the pin that the #One Button is attached to.
const int buttonTwo = 53; // the pin that the #Two Button is attached to.
const int buttonThree = 54; // the pin that the #Three Button is attached to.
const int buttonFour = 55; // the pin that the #Four Button is attached to.
const int buttonFive = 56; // the pin that the #Five Button is attached to.
const int buttonSix = 57; // the pin that the #Six Button is attached to.
const int buttonSeven = 58; // the pin that the #Seven Button is attached to.
const int buttonVFR = 59; // the pin that the VFR Button is attached to.
// Variables will change:
int buttonState1 = 0; // current state of the OFF Rotary Switch.
int buttonState2 = 0; // current state of the SBY Rotary Switch.
int buttonState3 = 0; // current state of the TST Rotary Switch.
int buttonState4 = 0; // current state of the ON Rotary Switch.
int buttonState5 = 0; // current state of the ALT Rotary Switch.
int buttonState6 = 0; // current state of the #Zero Button.
int buttonState7 = 0; // current state of the #One Button.
int buttonState8 = 0; // current state of the #Two Button.
int buttonState9 = 0; // current state of the #Three Button.
int buttonState10 = 0; // current state of the #Four Button.
int buttonState11 = 0; // current state of the #Five Button.
int buttonState12 = 0; // current state of the #Six Button.
int buttonState13 = 0; // current state of the #Seven Button.
int buttonState14 = 0; // current state of the VFR Button.


int j1;// For reading the Transponder code and the three first digits of Altitude from Link2fs.


#include <liquidcrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);






// ++++ JM ADDED
String SWstate, SWstate2, Xpndr, Xpndrold, ALTLevel, ALTLevelold; // used as Switch placement LCD text
int newRead [14]; // declare newRead as an array w/ 5 slots for the Rotary Switch
int oldRead [14]; // declare oldRead as an array w/ 5 slots for the Rotary Switch
boolean start;
long LoopCycle = 75000;
long debounce;
// +++++++++++








void setup() {

// initialize the button pin as a input:
pinMode(buttonOFF, INPUT);
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
pinMode(buttonZero, INPUT);
pinMode(buttonOne, INPUT);
pinMode(buttonTwo, INPUT);
pinMode(buttonThree, INPUT);
pinMode(buttonFour, INPUT);
pinMode(buttonFive, INPUT);
pinMode(buttonSix, INPUT);
pinMode(buttonSeven, INPUT);
pinMode(buttonVFR, INPUT);

//########## Initialize serial communication:
Serial.begin(115200);

//########## set up the 1.LCD's number of columns and rows:
lcd.begin(16,2);

Serial.flush();
}


void loop() {
// read the oldest byte in the serial buffer:
if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == 'm'){ // Found the reading "Transponder Code"
delay(11); // It seems to need a delay here
Xpndr= "";
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += (" "); //pads it up to 8 caracters
if (Xpndr != Xpndrold){ // checks to see if its different to the "old" reading
// delay (11);
lcd.setCursor(12, 1); //sets the cursor position for the first letter
delay (11);
lcd.print(Xpndr); //Prints the data to the LCD
Xpndrold = Xpndr; // Writes the current reading to the "old" string.
}
}
if (j1 == 'C'){ // Found the reading "altitude"
delay (11);
ALTLevel = "";
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += (" "); //pads it up to 8 caracters
if (ALTLevel != ALTLevelold){
//delay (11);
lcd.setCursor(0, 1);
delay (11);
lcd.print(ALTLevel);
ALTLevelold = ALTLevel;
}
}
}

//### Rotary Switch Read
buttonState1 = digitalRead(buttonOFF);
buttonState2 = digitalRead(buttonSBY);
buttonState3 = digitalRead(buttonTST);
buttonState4 = digitalRead(buttonON);
buttonState5 = digitalRead(buttonALT);
//### Zero to 7 + VFR Button Read
buttonState6 = digitalRead(buttonZero);
buttonState7 = digitalRead(buttonOne);
buttonState8 = digitalRead(buttonTwo);
buttonState9 = digitalRead(buttonThree);
buttonState10 = digitalRead(buttonFour);
buttonState11 = digitalRead(buttonFive);
buttonState12 = digitalRead(buttonSix);
buttonState13 = digitalRead(buttonSeven);
buttonState14 = digitalRead(buttonVFR);


// check to see if user takes too long
if (LoopCycle == 75000){start = false; SWstate = ""; Serial.println("TIME-OUT - ");LoopCycle = 75001;}


if(debounce == 1000){ //debounce rotary/push switch
newRead [0] = buttonState6; // Store in newRead Button "Zero" in slot0
newRead [1] = buttonState7; // Store in newRead Button "One" in slot1
newRead [2] = buttonState8; // Store in newRead Button "Two" in slot2
newRead [3] = buttonState9; // Store in newRead Button "Three" in slot3
newRead [4] = buttonState10; // Store in newRead Button "Four" in slot4
newRead [5] = buttonState11; // Store in newRead Button "Five" in slot5
newRead [6] = buttonState12; // Store in newRead Button "Six" in slot6
newRead [7] = buttonState13; // Store in newRead Button "Seven" in slot7
newRead [8] = buttonState14; // Store in newRead Button "VFR" in slot8
newRead [9] = buttonState1; // Store in newRead "OFF" Rotary Switch in newRead slot9
newRead [10] = buttonState2; // Store in newRead "SBY" Rotary Switch in newRead slot10
newRead [11] = buttonState3; // Store in newRead "TST" Rotary Switch in newRead slot11
newRead [12] = buttonState4; // Store in newRead "ON" Rotary Switch in newRead slot12
newRead [13] = buttonState5; // Store in newRead "ALT" Rotary Switch in newRead slot13


// Compare array slots to determine if LCD clear is needed
for (int arrayNUM = 0; arrayNUM <= 13; arrayNUM++) { // 0 based - 9 slots
if (newRead [arrayNUM] != oldRead [arrayNUM] ) //compare slot #s and clear LCD if needed
{ start = true; LoopCycle = 0; debounce = 0;}//lcd2.clear(); break;}
} // END for-next


} // END debounce of switch


if (start == true){

//### Zero Button
if (newRead [0] != oldRead [0] && buttonState6 == HIGH )
{SWstate += "0"; LCDprint();}
//### One Button
if (newRead [1] != oldRead [1] && buttonState7 == HIGH )
{SWstate += "1"; LCDprint();}
//### Two Button
if (newRead [2] != oldRead [2] && buttonState8 == HIGH )
{SWstate += "2"; LCDprint();}
//### Three Button
if (newRead [3] != oldRead [3] && buttonState9 == HIGH )
{SWstate += "3"; LCDprint();}
//### Four Button
if (newRead [4] != oldRead [4] && buttonState10 == HIGH )
{SWstate += "4"; LCDprint();}
//### Five Button
if (newRead [5] != oldRead [5] && buttonState11 == HIGH )
{SWstate += "5"; LCDprint();}
//### Six Button
if (newRead [6] != oldRead [6] && buttonState12 == HIGH )
{SWstate += "6"; LCDprint();}
//### Seven Button
if (newRead [7] != oldRead [7] && buttonState13 == HIGH )
{SWstate += "7"; LCDprint();}
//### VFR Button
if (newRead [8] != oldRead [8] && buttonState14 == HIGH )
{SWstate += "1200"; LCDprint();}

// Rotary OFF
if (newRead [9] != oldRead [9] && buttonState1 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" XPNDR OFF");
lcd.setCursor(0,1);
lcd.print(" XPNDR OFF");
delay (11);}


// Rotary SBY
if (newRead [10] != oldRead [10] && buttonState2 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" STANDBY FOR");
lcd.setCursor(0,1);
lcd.print(" SQUAWK CODE");
delay (11);}

// Rotary TST
if (newRead [11] != oldRead [11] && buttonState3 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print("R-SBY-TEST-ON--R");
lcd.setCursor(0,1);
lcd.print("R-SBY-TEST-ON--R");
delay (11);}

// Rotary ON
if (newRead [12] != oldRead [12] && buttonState4 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" ON R");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(12,1);
lcd.print(Xpndr);
delay (11);}

// Rotary ALT
if (newRead [13] != oldRead [13] && buttonState5 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" AL ALT");
lcd.setCursor(0,1);
lcd.print(ALTLevel);
lcd.setCursor(12,1);
lcd.print(Xpndr);
delay (11);}


// Check to see if SWstate contains 4 characters
if (SWstate.length() == 4){start = false; LinkFS_send();}


// Increase Time-out timer
LoopCycle = LoopCycle + 1;


} // END if (start == true)


debounce = debounce + 1; if (debounce == 2000){debounce =0;}
oldRead [0] = newRead [0]; // Store in oldRead slot0
oldRead [1] = newRead [1]; // Store in oldRead slot1
oldRead [2] = newRead [2]; // Store in oldRead slot2
oldRead [3] = newRead [3]; // Store in oldRead slot3
oldRead [4] = newRead [4]; // Store in oldRead slot4
oldRead [5] = newRead [5]; // Store in oldRead slot5
oldRead [6] = newRead [6]; // Store in oldRead slot6
oldRead [7] = newRead [7]; // Store in oldRead slot7
oldRead [8] = newRead [8]; // Store in oldRead slot8
oldRead [9] = newRead [9]; //Rotary Switch oldRead slot9
oldRead [10] = newRead [10];//Rotary Switch oldRead slot10
oldRead [11] = newRead [11];//Rotary Switch oldRead slot11
oldRead [12] = newRead [12];//Rotary Switch oldRead slot12
oldRead [13] = newRead [13];//Rotary Switch oldRead slot13


} // End void loop


void LCDprint(){
lcd.setCursor(12,1);
lcd.print(SWstate);
Serial.println ("ENTRY - " + SWstate);
} // End LCDprint


void LinkFS_send(){
SWstate = "W" + SWstate;
Serial.println (SWstate);
SWstate = "";
} // END LinkFS_send




All credits for the code, goes to JMeller! Thank you so much :p</liquidcrystal.h>

JMeller
05-07-2013, 11:31 PM
Removed - - - - -

JMeller
05-07-2013, 11:34 PM
Congrats on your success, Roy! Awesome!! Without a doubt, you are fully aware of what is happening within your code.

Now - so long as your are comfortable with understanding your code, let's trim it to the bare minimums:
start at:
debounce = debounce + 1; if (debounce == 2000){debounce =0;}

---- Remove all oldRead [X] = newRead [X] with the following:

for (int arrayNUM = 0; arrayNUM <= 13; arrayNUM++) { // 0 based - 14 slots; Save new to old
oldRead [arrayNUM] = newRead [arrayNUM]
} // END for-next
If you have any questions "WHY", feel free to post them.


Next, a suggestion, correct this - (I am also susceptible to copy/paste errors such as this)
//### VFR Button
if (newRead [8] != oldRead [8] && buttonState14 == HIGH )
{SWstate += "1200"; LCDprint();}
It should be SWstate = "1200" because you intend NOT to add text to the existing text of SWstate.

And finally, a challenge (should you accept it):
1.) At the very first button press, clear the LCD position(s) of the intended 4 digit xpdr code
2.) If the keypress timesout, display the current/old xpdr code.
3.) A bonus for using the lcd library flashing cursor during xpdr code entry!!




Again, Congratulations!
-James

BuzziBi
05-08-2013, 03:37 AM
Without a doubt, you are fully aware of what is happening within your code.

Without a doubt! Most of the time, I'm fully aware that I fumble around in the dark :roll:

My first thought was to use 14 slots for storing the old button's state. But to get the "Mode" in the first line lcd (0.0) and xpndr Read the second line lcd (0.1) I had to use 2 SWstate's, SWstate and SWstate2.
(Incidentally, SWstate2 lingers in the String based on this experiment!)
And no matter how much I tried, I could not get it to work. One argument overwrote the other. I certainly had an error I couldent see. It takes so little to make everything stop working. I sat and pondered a long time, before I saw that I had forgotten a } at one of the " if buttons arguments". And that definitely made an error! :D
Definitely a result of my laziness, that makes me all too often uses cope/paste, and ignored highlighting all text :D
I've probably been in a hurry to see the end result. When I've given it a little rest, maybe my thoughts will clear.
It was fun though, to get it working!

EDIT: PS to Jim. I hope the xpndr feature comes with the Link2fs Multi :p

Jim NZ
05-09-2013, 07:18 AM
Fumbling around in the dark ,, all sorts of pictures come to mind on that one :) :)

Anyway,, to answer your question ,, winters here now and minus 3 degrees C so I'm back into programming.

First off the block is "InOut" a few more extras in it, all known bugs fixed and it's only a few days away ,, I was hoping to get your Xponder code thing "hidden" in it but that side turned to custard. So keep using the "hack" I made you in the mean time.

The "Multi" will be fiddled with in a few days but only to fix a known bug.

The "transponder direct input" will be in the "Multi" when I add the simconnect inputs although I have these other "updates" pressing me first ,, but the good thing about that is ,,, I want that function as well !!! :)

Happy fiddling ,,, Jim

BuzziBi
09-26-2013, 12:22 PM
Hey.
I have now tried the code for the XPNDR, with the Multi_beta5f.
I get some errors and I fail to see where the cause lies.
See the pictures.
8169 8170
As you can see, the figures are completely overwritten/hidden at each update by the Multi_beta5f (here the last zero figure ). It is random which figures are overwritten and sometimes all the figures.
Suggestions?

This is the code that worked with link2fs_inout_v4

// This constant won't change:const int buttonOFF = 46; // the pin that the Rotary Switch is attached to.
const int buttonSBY = 47; // the pin that the Rotary Switch is attached to.
const int buttonTST = 48; // the pin that the Rotary Switch is attached to.
const int buttonON = 49; // the pin that the Rotary Switch is attached to.
const int buttonALT = 50; // the pin that the Rotary Switch is attached to.
const int buttonZero = 51; // the pin that the #Zero Button is attached to.
const int buttonOne = 52; // the pin that the #One Button is attached to.
const int buttonTwo = 53; // the pin that the #Two Button is attached to.
const int buttonThree = 54; // the pin that the #Three Button is attached to.
const int buttonFour = 55; // the pin that the #Four Button is attached to.
const int buttonFive = 56; // the pin that the #Five Button is attached to.
const int buttonSix = 57; // the pin that the #Six Button is attached to.
const int buttonSeven = 58; // the pin that the #Seven Button is attached to.
const int buttonVFR = 59; // the pin that the VFR Button is attached to.
// Variables will change:
int buttonState1 = 0; // current state of the OFF Rotary Switch.
int buttonState2 = 0; // current state of the SBY Rotary Switch.
int buttonState3 = 0; // current state of the TST Rotary Switch.
int buttonState4 = 0; // current state of the ON Rotary Switch.
int buttonState5 = 0; // current state of the ALT Rotary Switch.
int buttonState6 = 0; // current state of the #Zero Button.
int buttonState7 = 0; // current state of the #One Button.
int buttonState8 = 0; // current state of the #Two Button.
int buttonState9 = 0; // current state of the #Three Button.
int buttonState10 = 0; // current state of the #Four Button.
int buttonState11 = 0; // current state of the #Five Button.
int buttonState12 = 0; // current state of the #Six Button.
int buttonState13 = 0; // current state of the #Seven Button.
int buttonState14 = 0; // current state of the VFR Button.


int j1;// For reading the Transponder code and the three first digits of Altitude from Link2fs.


#include <liquidcrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);






// ++++ JM ADDED
String SWstate, SWstate2, Xpndr, Xpndrold, ALTLevel, ALTLevelold; // used as Switch placement LCD text
int newRead [14]; // declare newRead as an array w/ 5 slots for the Rotary Switch
int oldRead [14]; // declare oldRead as an array w/ 5 slots for the Rotary Switch
boolean start;
long LoopCycle = 75000;
long debounce;
// +++++++++++








void setup() {

// initialize the button pin as a input:
pinMode(buttonOFF, INPUT);
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
pinMode(buttonZero, INPUT);
pinMode(buttonOne, INPUT);
pinMode(buttonTwo, INPUT);
pinMode(buttonThree, INPUT);
pinMode(buttonFour, INPUT);
pinMode(buttonFive, INPUT);
pinMode(buttonSix, INPUT);
pinMode(buttonSeven, INPUT);
pinMode(buttonVFR, INPUT);

//########## Initialize serial communication:
Serial.begin(115200);

//########## set up the 1.LCD's number of columns and rows:
lcd.begin(16,2);

Serial.flush();
}


void loop() {
// read the oldest byte in the serial buffer:
if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == 'm'){ // Found the reading "Transponder Code"
delay(11); // It seems to need a delay here
Xpndr= "";
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += (" "); //pads it up to 8 caracters
if (Xpndr != Xpndrold){ // checks to see if its different to the "old" reading
// delay (11);
lcd.setCursor(12, 1); //sets the cursor position for the first letter
delay (11);
lcd.print(Xpndr); //Prints the data to the LCD
Xpndrold = Xpndr; // Writes the current reading to the "old" string.
}
}
if (j1 == 'C'){ // Found the reading "altitude"
delay (11);
ALTLevel = "";
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += (" "); //pads it up to 8 caracters
if (ALTLevel != ALTLevelold){
//delay (11);
lcd.setCursor(0, 1);
delay (11);
lcd.print(ALTLevel);
ALTLevelold = ALTLevel;
}
}
}

//### Rotary Switch Read
buttonState1 = digitalRead(buttonOFF);
buttonState2 = digitalRead(buttonSBY);
buttonState3 = digitalRead(buttonTST);
buttonState4 = digitalRead(buttonON);
buttonState5 = digitalRead(buttonALT);
//### Zero to 7 + VFR Button Read
buttonState6 = digitalRead(buttonZero);
buttonState7 = digitalRead(buttonOne);
buttonState8 = digitalRead(buttonTwo);
buttonState9 = digitalRead(buttonThree);
buttonState10 = digitalRead(buttonFour);
buttonState11 = digitalRead(buttonFive);
buttonState12 = digitalRead(buttonSix);
buttonState13 = digitalRead(buttonSeven);
buttonState14 = digitalRead(buttonVFR);


// check to see if user takes too long
if (LoopCycle == 75000){start = false; SWstate = ""; Serial.println("TIME-OUT - ");LoopCycle = 75001;}


if(debounce == 1000){ //debounce rotary/push switch
newRead [0] = buttonState6; // Store in newRead Button "Zero" in slot0
newRead [1] = buttonState7; // Store in newRead Button "One" in slot1
newRead [2] = buttonState8; // Store in newRead Button "Two" in slot2
newRead [3] = buttonState9; // Store in newRead Button "Three" in slot3
newRead [4] = buttonState10; // Store in newRead Button "Four" in slot4
newRead [5] = buttonState11; // Store in newRead Button "Five" in slot5
newRead [6] = buttonState12; // Store in newRead Button "Six" in slot6
newRead [7] = buttonState13; // Store in newRead Button "Seven" in slot7
newRead [8] = buttonState14; // Store in newRead Button "VFR" in slot8
newRead [9] = buttonState1; // Store in newRead "OFF" Rotary Switch in newRead slot9
newRead [10] = buttonState2; // Store in newRead "SBY" Rotary Switch in newRead slot10
newRead [11] = buttonState3; // Store in newRead "TST" Rotary Switch in newRead slot11
newRead [12] = buttonState4; // Store in newRead "ON" Rotary Switch in newRead slot12
newRead [13] = buttonState5; // Store in newRead "ALT" Rotary Switch in newRead slot13


// Compare array slots to determine if LCD clear is needed
for (int arrayNUM = 0; arrayNUM <= 13; arrayNUM++) { // 0 based - 9 slots
if (newRead [arrayNUM] != oldRead [arrayNUM] ) //compare slot #s and clear LCD if needed
{ start = true; LoopCycle = 0; debounce = 0;}//lcd2.clear(); break;}
} // END for-next


} // END debounce of switch


if (start == true){

//### Zero Button
if (newRead [0] != oldRead [0] && buttonState6 == HIGH )
{SWstate += "0"; LCDprint();}
//### One Button
if (newRead [1] != oldRead [1] && buttonState7 == HIGH )
{SWstate += "1"; LCDprint();}
//### Two Button
if (newRead [2] != oldRead [2] && buttonState8 == HIGH )
{SWstate += "2"; LCDprint();}
//### Three Button
if (newRead [3] != oldRead [3] && buttonState9 == HIGH )
{SWstate += "3"; LCDprint();}
//### Four Button
if (newRead [4] != oldRead [4] && buttonState10 == HIGH )
{SWstate += "4"; LCDprint();}
//### Five Button
if (newRead [5] != oldRead [5] && buttonState11 == HIGH )
{SWstate += "5"; LCDprint();}
//### Six Button
if (newRead [6] != oldRead [6] && buttonState12 == HIGH )
{SWstate += "6"; LCDprint();}
//### Seven Button
if (newRead [7] != oldRead [7] && buttonState13 == HIGH )
{SWstate += "7"; LCDprint();}
//### VFR Button
if (newRead [8] != oldRead [8] && buttonState14 == HIGH )
{SWstate += "1200"; LCDprint();}

// Rotary OFF
if (newRead [9] != oldRead [9] && buttonState1 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" XPNDR OFF");
lcd.setCursor(0,1);
lcd.print(" XPNDR OFF");
delay (11);}


// Rotary SBY
if (newRead [10] != oldRead [10] && buttonState2 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" STANDBY FOR");
lcd.setCursor(0,1);
lcd.print(" SQUAWK CODE");
delay (11);}

// Rotary TST
if (newRead [11] != oldRead [11] && buttonState3 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print("R-SBY-TEST-ON--R");
lcd.setCursor(0,1);
lcd.print("R-SBY-TEST-ON--R");
delay (11);}

// Rotary ON
if (newRead [12] != oldRead [12] && buttonState4 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" ON R");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(12,1);
lcd.print(Xpndr);
delay (11);}

// Rotary ALT
if (newRead [13] != oldRead [13] && buttonState5 == HIGH )
{lcd.clear();
lcd.setCursor(0,0);
delay (11);
lcd.print(" AL ALT");
lcd.setCursor(0,1);
lcd.print(ALTLevel);
lcd.setCursor(12,1);
lcd.print(Xpndr);
delay (11);}


// Check to see if SWstate contains 4 characters
if (SWstate.length() == 4){start = false; LinkFS_send();}


// Increase Time-out timer
LoopCycle = LoopCycle + 1;


} // END if (start == true)


debounce = debounce + 1; if (debounce == 2000){debounce =0;}
oldRead [0] = newRead [0]; // Store in oldRead slot0
oldRead [1] = newRead [1]; // Store in oldRead slot1
oldRead [2] = newRead [2]; // Store in oldRead slot2
oldRead [3] = newRead [3]; // Store in oldRead slot3
oldRead [4] = newRead [4]; // Store in oldRead slot4
oldRead [5] = newRead [5]; // Store in oldRead slot5
oldRead [6] = newRead [6]; // Store in oldRead slot6
oldRead [7] = newRead [7]; // Store in oldRead slot7
oldRead [8] = newRead [8]; // Store in oldRead slot8
oldRead [9] = newRead [9]; //Rotary Switch oldRead slot9
oldRead [10] = newRead [10];//Rotary Switch oldRead slot10
oldRead [11] = newRead [11];//Rotary Switch oldRead slot11
oldRead [12] = newRead [12];//Rotary Switch oldRead slot12
oldRead [13] = newRead [13];//Rotary Switch oldRead slot13


} // End void loop


void LCDprint(){
lcd.setCursor(12,1);
lcd.print(SWstate);
Serial.println ("ENTRY - " + SWstate);
} // End LCDprint


void LinkFS_send(){
SWstate = "W" + SWstate;
Serial.println (SWstate);
SWstate = ""; </liquidcrystal.h>} // END LinkFS_send
And here is the code for the Multi_beta5f.





int CodeIn;// used on all serial reads
int KpinNo;
int Koutpin;


const int buttonOFF = 37; // the pin that the Rotary Switch OFF is attached to.
const int buttonSBY = 38; // the pin that the Rotary Switch SBY is attached to.
const int buttonTST = 39; // the pin that the Rotary Switch TST is attached to.
const int buttonON = 40; // the pin that the Rotary Switch ON is attached to.
const int buttonALT = 41; // the pin that the Rotary Switch ALT is attached to.
const int buttonZero = 28; // the pin that the #Zero Button is attached to.
const int buttonOne = 29; // the pin that the #One Button is attached to.
const int buttonTwo = 30; // the pin that the #Two Button is attached to.
const int buttonThree = 31; // the pin that the #Three Button is attached to.
const int buttonFour = 32; // the pin that the #Four Button is attached to.
const int buttonFive = 33; // the pin that the #Five Button is attached to.
const int buttonSix = 34; // the pin that the #Six Button is attached to.
const int buttonSeven = 35; // the pin that the #Seven Button is attached to.
const int buttonVFR = 36; // the pin that the VFR Button is attached to.
// Variables will change:
int buttonState1 = 0; // current state of the OFF Rotary Switch.
int buttonState2 = 0; // current state of the SBY Rotary Switch.
int buttonState3 = 0; // current state of the TST Rotary Switch.
int buttonState4 = 0; // current state of the ON Rotary Switch.
int buttonState5 = 0; // current state of the ALT Rotary Switch.
int buttonState6 = 0; // current state of the #Zero Button.
int buttonState7 = 0; // current state of the #One Button.
int buttonState8 = 0; // current state of the #Two Button.
int buttonState9 = 0; // current state of the #Three Button.
int buttonState10 = 0; // current state of the #Four Button.
int buttonState11 = 0; // current state of the #Five Button.
int buttonState12 = 0; // current state of the #Six Button.
int buttonState13 = 0; // current state of the #Seven Button.
int buttonState14 = 0; // current state of the VFR Button.


#include <liquidcrystal.h>
LiquidCrystal lcd1(22, 23, 24, 25, 26, 27);


String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;


// ++++ JM ADDED
String SWstate, SWstate2, Xpndr, Xpndrold, ALTLevel, ALTLevelold; // used as Switch placement LCD text
int newRead [14]; // declare newRead as an array w/ 5 slots for the Rotary Switch
int oldRead [14]; // declare oldRead as an array w/ 5 slots for the Rotary Switch
boolean start;
long LoopCycle = 55000;
long debounce;
// +++++++++++


void setup()
{
Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";

for (int KoutPin = 50; KoutPin < 53; KoutPin++)// Get all the pins ready for "Keys"
{
pinMode(KoutPin, INPUT);
digitalWrite(KoutPin, HIGH);
}
// initialize the button pin as a input:
pinMode(buttonOFF, INPUT);
pinMode(buttonSBY, INPUT);
pinMode(buttonTST, INPUT);
pinMode(buttonON, INPUT);
pinMode(buttonALT, INPUT);
pinMode(buttonZero, INPUT);
pinMode(buttonOne, INPUT);
pinMode(buttonTwo, INPUT);
pinMode(buttonThree, INPUT);
pinMode(buttonFour, INPUT);
pinMode(buttonFive, INPUT);
pinMode(buttonSix, INPUT);
pinMode(buttonSeven, INPUT);
pinMode(buttonVFR, INPUT);

//########## Initialize serial communication:
Serial.begin(115200);
//########## set up the 1.LCD's number of columns and rows:
lcd1.begin(16,2);
}


void loop() {


{OTHER();}// Check for "Other" things to do. (Non extraction stuff)
if (Serial.available()) {
CodeIn = getChar();
if (CodeIn == '=') {EQUALS();} // The first identifier is "="
if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
}


}


char getChar()// Get a character from the serial buffer
{
while(Serial.available() == 0);// wait for data
return((char)Serial.read());// Thanks Doug
}
void OTHER(){
/* In here you would put code that uses other data that
cant be put into an "extraction void" that references something else.
Also in here you would put code to do something that was not
relying on a current extraction.
*/
//### Rotary Switch Read
buttonState1 = digitalRead(buttonOFF);
buttonState2 = digitalRead(buttonSBY);
buttonState3 = digitalRead(buttonTST);
buttonState4 = digitalRead(buttonON);
buttonState5 = digitalRead(buttonALT);
//### Zero to 7 + VFR Button Read
buttonState6 = digitalRead(buttonZero);
buttonState7 = digitalRead(buttonOne);
buttonState8 = digitalRead(buttonTwo);
buttonState9 = digitalRead(buttonThree);
buttonState10 = digitalRead(buttonFour);
buttonState11 = digitalRead(buttonFive);
buttonState12 = digitalRead(buttonSix);
buttonState13 = digitalRead(buttonSeven);
buttonState14 = digitalRead(buttonVFR);




// check to see if user takes too long
if (LoopCycle == 75000){start = false; SWstate = ""; Serial.println("TIME-OUT - ");LoopCycle = 75001;}




if(debounce == 1000){ //debounce rotary/push switch
newRead [0] = buttonState6; // Store in newRead Button "Zero" in slot0
newRead [1] = buttonState7; // Store in newRead Button "One" in slot1
newRead [2] = buttonState8; // Store in newRead Button "Two" in slot2
newRead [3] = buttonState9; // Store in newRead Button "Three" in slot3
newRead [4] = buttonState10; // Store in newRead Button "Four" in slot4
newRead [5] = buttonState11; // Store in newRead Button "Five" in slot5
newRead [6] = buttonState12; // Store in newRead Button "Six" in slot6
newRead [7] = buttonState13; // Store in newRead Button "Seven" in slot7
newRead [8] = buttonState14; // Store in newRead Button "VFR" in slot8
newRead [9] = buttonState1; // Store in newRead "OFF" Rotary Switch in newRead slot9
newRead [10] = buttonState2; // Store in newRead "SBY" Rotary Switch in newRead slot10
newRead [11] = buttonState3; // Store in newRead "TST" Rotary Switch in newRead slot11
newRead [12] = buttonState4; // Store in newRead "ON" Rotary Switch in newRead slot12
newRead [13] = buttonState5; // Store in newRead "ALT" Rotary Switch in newRead slot13




// Compare array slots to determine if LCD clear is needed
for (int arrayNUM = 0; arrayNUM <= 13; arrayNUM++) { // 0 based - 9 slots
if (newRead [arrayNUM] != oldRead [arrayNUM] ) //compare slot #s and clear LCD if needed
{ start = true; LoopCycle = 0; debounce = 0;}//lcd2.clear(); break;}
} // END for-next




} // END debounce of switch




if (start == true){

//### Zero Button
if (newRead [0] != oldRead [0] && buttonState6 == HIGH )
{SWstate += "0"; LCDprint();}
//### One Button
if (newRead [1] != oldRead [1] && buttonState7 == HIGH )
{SWstate += "1"; LCDprint();}
//### Two Button
if (newRead [2] != oldRead [2] && buttonState8 == HIGH )
{SWstate += "2"; LCDprint();}
//### Three Button
if (newRead [3] != oldRead [3] && buttonState9 == HIGH )
{SWstate += "3"; LCDprint();}
//### Four Button
if (newRead [4] != oldRead [4] && buttonState10 == HIGH )
{SWstate += "4"; LCDprint();}
//### Five Button
if (newRead [5] != oldRead [5] && buttonState11 == HIGH )
{SWstate += "5"; LCDprint();}
//### Six Button
if (newRead [6] != oldRead [6] && buttonState12 == HIGH )
{SWstate += "6"; LCDprint();}
//### Seven Button
if (newRead [7] != oldRead [7] && buttonState13 == HIGH )
{SWstate += "7"; LCDprint();}
//### VFR Button
if (newRead [8] != oldRead [8] && buttonState14 == HIGH )
{SWstate += "1200"; LCDprint();}

// Rotary OFF
if (newRead [9] != oldRead [9] && buttonState1 == HIGH )
{lcd1.clear();
lcd1.setCursor(0,0);
delay (11);
lcd1.print(" XPNDR OFF");
lcd1.setCursor(0,1);
lcd1.print(" XPNDR OFF");
delay (11);}




// Rotary SBY
if (newRead [10] != oldRead [10] && buttonState2 == HIGH )
{lcd1.clear();
lcd1.setCursor(0,0);
delay (11);
lcd1.print(" STANDBY FOR");
lcd1.setCursor(0,1);
lcd1.print(" SQUAWK CODE");
delay (11);}

// Rotary TST
if (newRead [11] != oldRead [11] && buttonState3 == HIGH )
{lcd1.clear();
lcd1.setCursor(0,0);
delay (11);
lcd1.print("R-SBY-TEST-ON--R");
lcd1.setCursor(0,1);
lcd1.print("R-SBY-TEST-ON--R");
delay (11);}

// Rotary ON
if (newRead [12] != oldRead [12] && buttonState4 == HIGH )
{lcd1.clear();
lcd1.setCursor(0,0);
delay (11);
lcd1.print(" ON R");
lcd1.setCursor(0,1);
lcd1.print(" ");
lcd1.setCursor(12,1);
lcd1.print(Xpndr);
delay (11);}

// Rotary ALT
if (newRead [13] != oldRead [13] && buttonState5 == HIGH )
{lcd1.clear();
lcd1.setCursor(0,0);
delay (11);
lcd1.print(" AL ALT");
lcd1.setCursor(0,1);
lcd1.print(ALTLevel);
lcd1.setCursor(12,1);
lcd1.print(Xpndr);
delay (11);}




// Check to see if SWstate contains 4 characters
if (SWstate.length() == 4){start = false; LinkFS_send();}




// Increase Time-out timer
LoopCycle = LoopCycle + 1;




} // END if (start == true)




debounce = debounce + 1; if (debounce == 2000){debounce =0;}
oldRead [0] = newRead [0]; // Store in oldRead slot0
oldRead [1] = newRead [1]; // Store in oldRead slot1
oldRead [2] = newRead [2]; // Store in oldRead slot2
oldRead [3] = newRead [3]; // Store in oldRead slot3
oldRead [4] = newRead [4]; // Store in oldRead slot4
oldRead [5] = newRead [5]; // Store in oldRead slot5
oldRead [6] = newRead [6]; // Store in oldRead slot6
oldRead [7] = newRead [7]; // Store in oldRead slot7
oldRead [8] = newRead [8]; // Store in oldRead slot8
oldRead [9] = newRead [9]; //Rotary Switch oldRead slot9
oldRead [10] = newRead [10];//Rotary Switch oldRead slot10
oldRead [11] = newRead [11];//Rotary Switch oldRead slot11
oldRead [12] = newRead [12];//Rotary Switch oldRead slot12
oldRead [13] = newRead [13];//Rotary Switch oldRead slot13




} // End void loop




void LCDprint(){
lcd1.setCursor(12,1);
lcd1.print(SWstate);
Serial.println ("ENTRY - " + SWstate);
} // End LCDprint




void LinkFS_send(){
SWstate = "A42" + SWstate;
Serial.println (SWstate);
SWstate = "";
} // END LinkFS_send










void EQUALS(){ // The first identifier was "="
CodeIn = getChar(); // Get another character
switch(CodeIn) {// Now lets find what to do with it
case 'J'://Found the second identifier "TRANSPONDER CODE"
Xpndr= "";
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += char(Serial.read());
Xpndr += (" "); //pads it up to 8 caracters
if (Xpndr != Xpndrold){ // checks to see if its different to the "old" reading
// delay (11);
lcd1.setCursor(12, 1); //sets the cursor position for the first letter
//delay (11);
lcd1.print(Xpndr); //Prints the data to the LCD
Xpndrold = Xpndr; // Writes the current reading to the "old" string.
}
break;




//etc etc etc
}
}
void LESSTHAN(){ // The first identifier was "<"
CodeIn = getChar(); // Get another character
switch(CodeIn) {// Now lets find what to do with it
case 'D'://Found the second identifier "ALTITUDE"
ALTLevel = "";
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += char(Serial.read());
ALTLevel += (" "); //pads it up to 8 caracters
if (ALTLevel != ALTLevelold){
//delay (11);
lcd1.setCursor(0, 1);
//delay (11);
lcd1.print(ALTLevel);
ALTLevelold = ALTLevel;
}
}
}


void QUESTION(){ // The first identifier was "?"
CodeIn = getChar(); // Get another character
switch(CodeIn) {// Now lets find what to do with it
case 'A'://Found the second identifier
//Do something
break;

case 'B':
//Do something
break;

case 'C':
//Do something
break;

//etc etc etc
}
}
void SLASH(){ // The first identifier was "/" (Annunciator)
//Do something
}
















</liquidcrystal.h>

BuzziBi
09-27-2013, 07:45 AM
I am so pleased with myself :cool:
After many changes in the code, even thought the Arduino board had the wrong output voltage, but after a battery change in voltmeter, this turned out not to be the case.
Anyway, I found the solution.
When I put a delay in the code, the problem was gone!
There are certainly many who is better than me in writing code, who can explain this better than I can, but I think it has something with the receiving and sending time between FSX and Multi_beta5f.

Here is the change I did in the code:

void loop() {


{OTHER();}// Check for "Other" things to do. (Non extraction stuff)
if (Serial.available()) {
CodeIn = getChar();
if (CodeIn == '=') {EQUALS();} // The first identifier is "="
if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)
}


}


char getChar()// Get a character from the serial buffer
{
while(Serial.available() == 0);// wait for data
delay (11); //INSERTED A DELAY HERE
return((char)Serial.read());// Thanks Doug
}
void OTHER(){
/* In here you would put code that uses other data that
cant be put into an "extraction void" that references something else.
Also in here you would put code to do something that was not
relying on a current extraction.
*/

JMeller
09-27-2013, 09:05 AM
It's great you figured it out on your own. I read over the entire code and couldn't find how the character was being robbed. Since you had to add a delay, it appears return((char)Serial.read()) is stealing the character even at the same time the EQUALS() loop is trying to read the xpdr data. Good to know. Thanks, Roy.

BuzziBi
09-27-2013, 12:20 PM
Hei JMeller!
Thought you were on the beach at Playa Del something. Long time since I saw you here. :D
Yes, I was very pleased when I got it to work.
But I'm not so sure that the code, as it is now, quite as I want it.
I'm trying now to add Rotary Encoder's and KEY's and then the code for the XPNDR stops working.
Am just getting started with this and I have not got it to work yet. But as with everything else, a little self-torture and a lot of help from you "clever" guys, everythng will be solved eventually!