MadMaori
07-29-2012, 10:08 PM
Hey guys was wondering if anyone had a quick minute to explain to me what im doing wrong, i have a sketch for all my Autopilot Leds but for some reason there first If argument is the only one that works, i know all the Leds are hooked up correctly cause if i change the OUTPUT argument to suit every single one they all light up, im guessing its just somthing im not putting in between each IF, any help at all would rok guys!
code:
[/code
int xx;
String ap, apold, loc, locold, athr, athrold, alt, altold, apr, aprold;
void setup() {
//int APSwitch = A1; // Connected Flight Director Switches (A0)
//int AP2Switch = A2; // Connected Auto Throttle Switch (A1)
//int ALTSwitch = A3; // Connected to GPS vs NAV Switch (A2)
//int ILSSwitch = A4; // Connected Flight Director Switches (A0)
//int APTHRSwitch = A5;
//int LOCSwitch = A6;// Connected Auto Throttle Switch (A1)
//int APPRSwitch = A7; // Connected to GPS vs NAV Switch (A2)
pinMode(33,OUTPUT);//AP
pinMode(31,OUTPUT);//AP2
pinMode(29,OUTPUT);//ILS
pinMode(27,OUTPUT);//LOC
pinMode(39, OUTPUT);//ATHR
pinMode(35, OUTPUT);//ALT
pinMode(41, OUTPUT);//APP
//pinMode(APSwitch, INPUT);
// pinMode(AP2Switch, INPUT);
// pinMode(ALTSwitch, INPUT);
// pinMode(ILSSwitch, INPUT);
// pinMode(LOCSwitch, INPUT);
// pinMode(APTHRSwitch, INPUT);
//digitalWrite(APSwitch, HIGH);
//digitalWrite(APPRSwitch, HIGH);
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'b'){
delay (11);
ap = "";
ap += (char)Serial.read();
if (ap != apold){
if (ap == "0") {digitalWrite(33, LOW);}
if (ap == "1") {digitalWrite(33, HIGH);} {
apold = ap;
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'x'){
delay (11);
loc = "";
loc += (char)Serial.read();
loc += (char)Serial.read();
loc += (char)Serial.read();
if (loc != locold){
if (loc == "0") {digitalWrite(27, LOW);}
if (loc == "1") {digitalWrite(27, HIGH);}
locold = loc;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'E'){
delay (11);
athr = "";
athr += (char)Serial.read();
if (athr != athrold){
if (athr == "0") {digitalWrite(39, LOW);}
if (athr == "1") {digitalWrite(39, HIGH);}
athrold = athr;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 's'){
delay (11);
alt = "";
alt += (char)Serial.read();
if (alt != apold){
if (alt == "0") {digitalWrite(35, LOW);}
if (alt == "1") {digitalWrite(35, HIGH);}
altold = alt;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx== 'v'){
delay (11);
apr = "";
apr += (char)Serial.read(); //Read the first charactor sent
if (apr != aprold){
if (apr == "0") {digitalWrite(41, LOW);}
if (apr == "1") {digitalWrite(41, HIGH);} {
aprold = apr;
}
delay(50);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/code]
code:
[/code
int xx;
String ap, apold, loc, locold, athr, athrold, alt, altold, apr, aprold;
void setup() {
//int APSwitch = A1; // Connected Flight Director Switches (A0)
//int AP2Switch = A2; // Connected Auto Throttle Switch (A1)
//int ALTSwitch = A3; // Connected to GPS vs NAV Switch (A2)
//int ILSSwitch = A4; // Connected Flight Director Switches (A0)
//int APTHRSwitch = A5;
//int LOCSwitch = A6;// Connected Auto Throttle Switch (A1)
//int APPRSwitch = A7; // Connected to GPS vs NAV Switch (A2)
pinMode(33,OUTPUT);//AP
pinMode(31,OUTPUT);//AP2
pinMode(29,OUTPUT);//ILS
pinMode(27,OUTPUT);//LOC
pinMode(39, OUTPUT);//ATHR
pinMode(35, OUTPUT);//ALT
pinMode(41, OUTPUT);//APP
//pinMode(APSwitch, INPUT);
// pinMode(AP2Switch, INPUT);
// pinMode(ALTSwitch, INPUT);
// pinMode(ILSSwitch, INPUT);
// pinMode(LOCSwitch, INPUT);
// pinMode(APTHRSwitch, INPUT);
//digitalWrite(APSwitch, HIGH);
//digitalWrite(APPRSwitch, HIGH);
Serial.begin(115200);
}
void loop() {
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'b'){
delay (11);
ap = "";
ap += (char)Serial.read();
if (ap != apold){
if (ap == "0") {digitalWrite(33, LOW);}
if (ap == "1") {digitalWrite(33, HIGH);} {
apold = ap;
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'x'){
delay (11);
loc = "";
loc += (char)Serial.read();
loc += (char)Serial.read();
loc += (char)Serial.read();
if (loc != locold){
if (loc == "0") {digitalWrite(27, LOW);}
if (loc == "1") {digitalWrite(27, HIGH);}
locold = loc;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 'E'){
delay (11);
athr = "";
athr += (char)Serial.read();
if (athr != athrold){
if (athr == "0") {digitalWrite(39, LOW);}
if (athr == "1") {digitalWrite(39, HIGH);}
athrold = athr;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx == 's'){
delay (11);
alt = "";
alt += (char)Serial.read();
if (alt != apold){
if (alt == "0") {digitalWrite(35, LOW);}
if (alt == "1") {digitalWrite(35, HIGH);}
altold = alt;
}
if (Serial.available() > 0) {
xx = Serial.read();
if (xx== 'v'){
delay (11);
apr = "";
apr += (char)Serial.read(); //Read the first charactor sent
if (apr != aprold){
if (apr == "0") {digitalWrite(41, LOW);}
if (apr == "1") {digitalWrite(41, HIGH);} {
aprold = apr;
}
delay(50);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
/code]