Invalid Conversion *Updated now: ISO C++ forbids comparison between pointer an

  • edited with the proper comparison, but now its a different error

Can someone tell my why this code is giving an error.

/* 
A2A Annunciators
*/


int CodeIn;
String AmpLow;
const int AmpG = 2, AmpR = 3;

void setup(){
   Serial.begin(115200); 
    pinMode(AmpR, OUTPUT);
	  pinMode(AmpG, OUTPUT);
}

void loop() {
  {OTHER();}// Check for "Other" things to do. (Non extraction stuff)
  if (Serial.available()) {  //Check if anything there
    CodeIn = getChar();      //Get a serial read if there is.
//    if (CodeIn == '=') {EQUALS();} // The first identifier is "=" ,, goto void EQUALS
//    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<" ,, goto void LESSTHAN
//    if (CodeIn == '?') {QUESTION();}// The first identifier is "?" ,, goto void QUESTION
//    if (CodeIn == '/') {SLASH();}// The first identifier is "/"  ,, goto void SLASH (Annunciators)
	if (CodeIn == '#') {HASH();}// The first identifier is "#"  ,, goto void Hashtag (Custom offsets)
  }
}

char getChar()// Get a character from the serial buffer(Dont touch)
{
  while(Serial.available() == 0);// wait for data (Dont touch)
  return((char)Serial.read());// (Dont touch) 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.
(Remember - The identifier voids only trigger when it receives that identifier)
*/
}

void HASH(){      // The first identifier was "#"
       CodeIn = getChar(); // Get another character
  switch(CodeIn) {// Now lets find what to do with it
    case 'c'://Found the second identifier
     AmpLow = "";
	   AmpLow += getChar();
	   AmpLow += getChar();
	   AmpLow += getChar();
	   int AmpLow1 = AmpLow.toInt();
	   //Serial.println(AmpLow);
	   //Serial.println(AmpLow1);
	   
	   if (AmpLow1 <= "-1"){digitalWrite(AmpG, HIGH); digitalWrite(AmpR, HIGH);}else{digitalWrite(AmpG, LOW); digitalWrite(AmpR, LOW);}
	   
	   if (AmpLow1 <= "-3"){digitalWrite(AmpG, LOW); digitalWrite(AmpR, HIGH);}else{digitalWrite(AmpR, LOW);}
	   
    break;
     

       //etc etc etc
       // You only need the "Case" testing for the identifiers you expect to use.
     }
}

When this code that does the same thing basically, does not error

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

String KoldpinStateSTR, KpinStateSTR, Kstringnewstate,Kstringoldstate;

void setup() 
{
  Kstringoldstate = "111111111111111111111111111111111111111111111111111111111111111111111";
  
  for (int KoutPin = 8; KoutPin < 70; KoutPin++)// Set's up all the input pins  
  {
    pinMode(KoutPin, INPUT);
    digitalWrite(KoutPin, HIGH);  
  }
  pinMode(2, OUTPUT); // Flaps are "not up" LED
  pinMode(3, OUTPUT); // Flaps are down 1st position LED
  pinMode(4, OUTPUT); // Flaps are down 2nd position LED
 Serial.begin(115200);   
}

void loop() {
  {KEYS();} //Check the "keys" section
  if (Serial.available()) {
    CodeIn = getChar();//get a character
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
  }//end of serial check
}//end of void loop

char getChar()// Get a character from the serial buffer
{
  while(Serial.available() == 0);// wait for data
  return((char)Serial.read());// Thanks Doug
}

void LESSTHAN(){    // The first identifier was "<"
CodeIn = getChar(); // Get another character
  switch(CodeIn) {// Now lets find what to do with it
    case 'G'://Found the second identifier ("G" Flaps position)
      flaps = "";
      flaps += getChar();
      flaps += getChar();
      flaps += getChar();
      int flapsInt = flaps.toInt(); // convert it to an integer (Thanks Phill)
      if (flapsInt > 0) {digitalWrite(2, HIGH);} else {digitalWrite(2, LOW);}
      if (flapsInt > 5) {digitalWrite(3, HIGH);} else {digitalWrite(3, LOW);}
      if (flapsInt > 40) {digitalWrite(4, HIGH);} else {digitalWrite(4, LOW);}
    break;
     }
}

void KEYS() 
{
  Kstringnewstate = "";
  for (int KpinNo = 8; KpinNo < 70; KpinNo++){//check for inputs on pins 8 to 70
    KpinStateSTR = String(digitalRead(KpinNo)); //if you change the 8 in the line above ,, also change the 8 in the line below
    KoldpinStateSTR = String(Kstringoldstate.charAt(KpinNo - 8));
    if (KpinStateSTR != KoldpinStateSTR)//yes it's different
    {
      if (KpinNo != 13){ //pin 13 is no good as an input, it can "flutter" unless set up correctly
      if (KpinNo == 8 && KpinStateSTR == "0"){Serial.println ("C15");} //flap handle up a bit
      if (KpinNo == 9 && KpinStateSTR == "0"){Serial.println ("C14");} //flap handle down a bit
      if (KpinNo > 9){//now the keys bit
      Serial.print ("D"); 
      if (KpinNo < 10) Serial.print ("0");
      Serial.print (KpinNo);
      Serial.println (KpinStateSTR);
      }//end of keys bit
     }//end of its not pin 13
    }//end of yes its different
    Kstringnewstate += KpinStateSTR;
  }//end of 'For' loop
  Kstringoldstate = Kstringnewstate;
}// end of "inputs" void

thanks
StevenT

      if (AmpLow1 = "-1") {Should that be a comparison ?

ugh. the second “<=”!
OK now i get a different error!

forbids comparison between pointer and integer
its the same thing as the other code thats fine!

Post the error!

Mark

holmes4: Post the error!

Mark

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

A2AAnnunciators.ino: In function 'void HASH()': A2AAnnunciators:56: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] A2AAnnunciators:58: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] ISO C++ forbids comparison between pointer and integer [-fpermissive]

 if (AmpLow1 <= "-1"){digitalWrite(AmpG, HIGH); digitalWrite(AmpR, HIGH);}else{digitalWrite(AmpG, LOW); digitalWrite(AmpR, LOW);}
	   
	   if (AmpLow1 <= "-3"){digitalWrite(AmpG, LOW); digitalWrite(AmpR, HIGH);}else{digitalWrite(AmpR, LOW);}

First - from your post it is hard to tell which of the 2 bits of code you are taking about - make every effort to help us help you - piss us off and we will just stop trying to help you

Second - All ways auto-format your code before posting it (IDE → tools) again it helps us help you! Tip auto formating your code will help you to help your self.

Third - Look at the code above you can’t do <= with Strings! == Yes != Yes, but that’s it. Think about it.

Tip the most important thing about an error message is the line number. Ignore the message it’s self as that is only what the compiler thinks you where tying to there! and it is often wrong!

Mark

PS Until you have at least a first degree in software design/programming (NOT ITC) do not use String with the Arduino

PPS See Robin2 post on Serial input basics. And total re design your program! Your getChar() function is a total NO NO!

M

–First - from your post it is hard to tell which of the 2 bits of code you are taking about - make every effort to help us help you - piss us off and we will just stop trying to help you

I thought it was clear witch code is giving the error (The first code block). The second code block is not giving any errors and works.
“piss us off and we will just stop trying to help you” Where did this come from? Did I sound condescending or something? If I said something that gives that impression, I’m truly sorry. It is not my intention.

–Second - All ways auto-format your code before posting it (IDE → tools) again it helps us help you! --Tip auto formating your code will help you to help your self.

Didnt know of this feature. Im simply using other code from other people for a specific use.
This code is for intercommunication of Flight Simulator and the arduino via an intermediary software.

–Third - Look at the code above you can’t do <= with Strings! == Yes != Yes, but that’s it. Think about it.

I didn’t know that strings can only be compared as == or !=, but I thought with the “toInt” before the comparison, it would no longer be a string.
Im not a programmer. I’m a hobbyist working with bits of other peoples code to get things to do what I would like.

–Tip the most important thing about an error message is the line number. Ignore the message it’s self as that is only what the compiler thinks you where tying to there! and it is often wrong!

I do understand this but its not helping in this case (for me that is), the code that works without error has the same comparison.

–Mark

–PS Until you have at least a first degree in software design/programming (NOT ITC) do not use String with the Arduino

again Im not a programmer, I don’t understand why this is so, also as the second code block has such a String reference and that code works. this is where i’m confused.

–PPS See Robin2 post on Serial input basics. And total re design your program! Your getChar() function is a total NO NO!

I will try to find this post, but is it bad form or that it should not work. If the latter, it works fine with three other codes I run with the “getChar()”

Again my apologizes if I said something to Piss you or someone off. If I did please point it out directly and I will edit my tone and/or response.

thanks
StevenT

AmpLow1 may be an int but “anything” is a string no matter what. “-1” is a string NOT a number.

The first sticky post at the top of this forum will give you robin2 post on serial input basics and a lot else. Also the first post on the project guidance forum is an absolute.

Your getChar function is a no no as it blocks waiting for input meaning that nothing else can happen while it is running!. This may work in very simple programs but … Learn to do it right from the very beginning.

Mark

Thank you for the help! Ive banged my head against the desk for to long then I noticed my issue!

I had the -1 and -3 in quotes! making it a string!!! I feel really dumb now!

:o

oh well. Thanks again StevenT