Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Multiple cases

  1. #1
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Multiple cases

    Hello all

    I have almost finished my annunciation panel and almost have all the indications working. There are a couple of things I am unsure of. Firstly one of my indications lets me know if my gear is up if my manifold pressure drops below 14 inHG (6.3psi on Link2fs). For this to work though it has to know my manifold pressure and the condition of my gear. Is it possible to use 2 cases together or is there another way?

    Secondly, not all my annunciations an be activated from the annunciator page so I have set 5 up from within the annunciator page and 3 using simconnect extractions. How could I include a press to test button to light up all the lights? I have done it as a stand alone script but not sure how to incorporate it into this one. I have posted my current script below. I have tweaked Jims code and remove the piezo and the flashy light.

    Many thanks
    Marc





    Code:
    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
    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 Anunbutton = 12;// Button to test all annunciations
    int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button
    int KpinNo; 
    int Koutpin;
    String start;
    String pitot;
    String warn;
    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);
      }
      pinMode(Anunbutton, INPUT); // Cancell button on Anunnciators 
      digitalWrite(Anunbutton, HIGH);
      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' && 'Y':
        warn = "";
        warn += getChar();
        warn += getChar();
        warn += getChar();
        gear = ""; 
        gear += getChar();
        gear += getChar();
        gear += getChar();
        
        int warnInt = warn.toInt();
        int gearInt = gear.toInt();
        if (warnInt <6.3 && gearInt <2) {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;
      }

  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Is it this part you are trying to get to work?

    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'Q' && 'Y':
    warn = "";
    warn += getChar();
    warn += getChar();
    warn += getChar();
    gear = "";
    gear += getChar();
    gear += getChar();
    gear += getChar();

    int warnInt = warn.toInt();
    int gearInt = gear.toInt();
    if (warnInt <6.3 && gearInt <2) {digitalWrite(7, HIGH);}else {digitalWrite(7, LOW);}
    }
    }
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Hi, thanks for the reply. Yes that's the bit. To be honest I had no idea what to try. tried a couple of things that did not compile. That did compile but did not work. I used gear position in the void QUESTION as it was in the same as the manifold pressure so thought that would make things easier. I'm not quite sure how to approach it to get it working.

    Thanks
    Marc

  4. #4
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Still not able to test, because my workbench is hidden under to many other projects. But I can not help but ponder how to solve problems!
    Can this work?

    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it


    int warnalarm;
    int gearalarm;
    {
    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);}
    }
    }

    There are for sure ways to solve it, but since no one answered, I gave it a try.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  5. #5
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Hi, tried it but couldn't get it to work. Can I confirm that the int warnalarm and int gearalarm go at the top before the void setup. This is where I put them.

    Regards
    Marc

  6. #6
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Try inside the void QUESTION

    try add this below the
    if (warnalarm == 1 && gearalarm == 1) {digitalWrite(7, HIGH);}else {digitalWrite(7, LOW);}

    Serial.println("warnalarm");
    Serial.println(warnalarm);
    Serial.println();
    Serial.println("gearalarm");
    Serial.println(gearalarm);
    Serial.println();

    and use serial monitor to se if alarm changes.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  7. #7
    75+ Posting Member
    Join Date
    Nov 2011
    Location
    UK
    Posts
    77
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Hi BuzziBi, I have tried the above but there are no alarm changes coming through. Here is the script as it is now just in case I have hashed something else up. I am getting all of the information being sent from fsx to the card eg

    ?Q12.4?Y000
    /E0/F0
    /H0/N0/R0
    ?Q12.4?Y000
    ?Q12.4?Y000

    but cant see any alarm changes





    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
    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 Anunbutton = 12;// Button to test all annunciations
    int AnunPinTot = 0;//Used for cancelling alarms if fault disappears before pushing button
    int KpinNo;
    int Koutpin;
    int warnalarm;
    int gearalarm;
    String gear;
    String start;
    String pitot;
    String warn;
    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);
    }
    pinMode(Anunbutton, INPUT); // Cancell button on Anunnciators
    digitalWrite(Anunbutton, HIGH);
    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':{
    warn = "";
    warn += getChar();
    warn += getChar();
    warn += getChar();
    int warnInt = warn.toInt();
    if (warnInt <6.3) {warnalarm = 1;}
    else
    {warnalarm = 0;}
    break;
    }

    case 'Y':{
    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);}


    Serial.println("warnalarm");
    Serial.println(warnalarm);
    Serial.println();
    Serial.println("gearalarm");
    Serial.println(gearalarm);
    Serial.println();
    }
    }


    void SLASH(){ // The first identifier was "/" (Annunciators)
    CodeIn = getChar();
    for (count=0;count<7;count++) {
    if (CodeIn == AnunIdent2[count]){
    AnunPinValNew[count] = (getChar()- 4;
    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;
    }

  8. #8
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    I think I've figured out why it is not working.
    It's about converting a string to a int.
    This is out of my comfort zone
    It would have been easy if you could use <6 as a trigger rather then the <6.3 though.
    I have been doing some codeing but I did not find out of how to do the convertion.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  9. #9
    75+ Posting Member
    Join Date
    Aug 2015
    Location
    Montreal
    Posts
    106
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site


  10. #10
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Multiple cases

    Quote Originally Posted by SimSupervisor View Post
    Been there, done that!
    Great if you can show how to do this. I have been trying, but failed over and over again!
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

Page 1 of 2 12 LastLast