Results 1 to 3 of 3
  1. #1
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Error converting String to Int ???

    Jim,

    I finally have my test bench back up and running and I am now replacing my old code using the examples you give, like the Multi Flaps with LEDs code.

    For part of my code I need to read the Master Bus and Avionics Bus Voltage and drive digital outs high or low based on a voltage threshold. It looked like your flaps code would do it for me but I keep getting a compile error. I changed the variable name to fit my need but I don't believe I made any other changes yet it won't complie.

    This line: int MstrBusVolt = MstrBusVolt.toInt();which if I understand your sample code should convert my string variable MstrBusVolt to an integer keeps returning the following compile error error: request for member 'toInt' in 'MstrBusVolt', which is of non-class type 'int'

    Any thoughts on what I might be doing wrong?

    Here's the pertinent portion of the code:

    Code:
    int count = 0; //for array reading
    int CodeIn;// Gets the serial read
    
    int RlyChn1 = 4;
    int RlyChn2 = 5;
    
    
    String MstrBusVolt;
    String AvncsBusVolt;
    
    void setup() {
    
      pinMode(RlyChn1, OUTPUT);
      digitalWrite(RlyChn1, HIGH);
      pinMode(RlyChn2, OUTPUT);
      digitalWrite(RlyChn2, HIGH);
    
    
      Serial.begin(115200);
    }
    
    
    void loop() {
    
    
      {OTHER();}
      {ANNUNBUTTON();}
      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(){
       // Code for non extraction functions here
    }
    
    
    void EQUALS(){      
    
    
       // Code for "=" extraction functions here  }
    
    
    }
    
    
    void LESSTHAN(){    // The first identifier was "<"
    
    
       // Code for "<" extraction functions here  }
    
    
    }
    
    
    void QUESTION(){    // The first identifier was "?"
    
    
    CodeIn = getChar();
    
    
      switch(CodeIn) {// Now lets find what to do with it
    
    
        case 'K':
          MstrBusVolt = "";
          MstrBusVolt += getChar();
          MstrBusVolt += getChar();
          MstrBusVolt += getChar();
          MstrBusVolt += getChar();
          int MstrBusVolt = MstrBusVolt.toInt(); 
          if (MstrBusVolt < 18) {digitalWrite(RlyChn1, HIGH);} else {digitalWrite(RlyChn1, LOW);}
        break;
    
    
        case 'U':
          AvncsBusVolt = "";
          AvncsBusVolt += getChar();
          AvncsBusVolt += getChar();
          AvncsBusVolt += getChar();
          AvncsBusVolt += getChar();
          int AvncsBusVolt = AvncsBusVolt.toInt();
          if (AvncsBusVolt < 18) {digitalWrite(RlyChn2, HIGH);} else {digitalWrite(RlyChn2, LOW);}
        break;
    
    
         }
    
    
    }
    
    
    void SLASH(){    // The first identifier was "/" (Annunciators)
    
    
       // Code for "/" extraction functions here  }
    
    
    
    }
    THANKS!!!
    Tom G.
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  2. #2
    300+ Forum Addict Tom_G_2010's Avatar
    Join Date
    Mar 2011
    Location
    Central Mass
    Posts
    437
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Error converting String to Int ???

    Problem Solved!

    I was trying to re use the string variable name and you can't do that.

    Here's the line of code I had written:
    int MstrBusVolt = MstrBusVolt.toInt();

    Here's what I should have written:
    int MstrBusVoltInt = MstrBusVolt.toInt();

    Writing code late at night makes for some creative mistakes...
    https://www.facebook.com/mycessnasim PC: Intel Core i7 Haswell @ 3.8GHz, 8Gb Ram, Win 7 64Bit, dual SSDs, GeFroce 780 SIM: FSX w/Aclrtn Pk, FSUIPC4, ASN, UTX, GEX, REX 4

  3. #3
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Error converting String to Int ???

    We knew you would get it Tom.
    Marvelous what a wee sleep does to the brain-box
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !