Go Down

Topic: Newbie Scetch help (Read 656 times) previous topic - next topic

Good day

Please help me fix this code to maker it compile & work.

I get the following error when I compile my scetch: "ISO C++ forbids comparison between pointer and integer"

Here is the scetch:

Code: [Select]
int command = 0 ;

void setup() {
  // put your setup code here, to run once:
  delay(1000);          // wait a bit before starting
  Serial.begin(115200);   // set up Serial library at 9600 bps
}

void loop() {
  // put your main code here, to run repeatedly:
    if (Serial.available() > 0) {
    command = Serial.read();
    if (command == "1")
//pan left
    if (command == "2")
//pan center
    if (command == "3")
//pan right
    if (command == "4")
//tilt up
    if (command == "5")
//tilt center
    if (command == "6")
//tilt down
   
    command = 0; 
}
}


The error is displayed first on the following line:  if (command == "1")

AWOL

#1
Mar 24, 2011, 08:35 am Last Edit: Mar 24, 2011, 09:02 am by AWOL Reason: 1
Code: [Select]
(command == '1')
NB single quotes.

Quote
"ISO C++ forbids comparison between pointer and integer"

"command" is the integer, and in your version, "1" is a string, so is represented by a pointer.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Good day

Thank you very much for your help.
Will this change still be able to read the serial port data beeing sent to my Arduino?

Thanks
Riaan Deyzel

AWOL

Yes.
'1' is the integer value 49 decimal, 0x31
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Thank you very much.

I will try it this weekend.
I am busy playing around with apps that moves servo's around, and this code will be used for the following example.

http://arduino.cc/forum/index.php/topic,55429.0.html

Pitty the "Here is that example slightly modifed to have more buttons" project it is not in c# source code with scetch, but as they say, beggars can't be choosers.

Thanks again for the help.

Use single quotes to read the ASCII value not double quotes...Double quotes are used to print or scan the string...

Go Up