Go Down

Topic: Serial Monitor issues (Read 191 times) previous topic - next topic

TechGenius866

Aug 22, 2019, 09:06 pm Last Edit: Aug 27, 2019, 03:49 pm by TechGenius866
Hello! I have been trying to make a good (old fashioned?) "Launching Nuclear Missiles" thing using an lcd and the Serial Monitor. I was beginning to have some luck with this, but i ran into an error... "ISO C++ forbids comparison between pointer and integer [-fpermissive]." Can someone help? I have a comment in the code that shows what/where the error is.



Code: [Select]
#include <LiquidCrystal.h>

char serialData;
const int rs = 12, en = 10, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
 lcd.begin(16, 2);
 Serial.begin(9600);
}

void loop() {
 lcd.write("Awaiting");
 lcd.setCursor(0,1);
 lcd.write("Commands");
 lcd.setCursor(0,0);
 if(Serial.available())
 {
   serialData = Serial.read();

   if(serialData == "Activate") // << Issue
   {
   delay(100);
   Serial.println("Working");
   lcd.clear();
   lcd.write("Hello");
   delay(1000);
   lcd.clear();
   lcd.write("World");
   delay(1000);
   lcd.clear();
   lcd.write("");
   delay(1000);
   lcd.clear();
   lcd.write("10");
   delay(1000);
   lcd.clear();
   lcd.write("9");
   delay(1000);
   lcd.clear();
   lcd.write("8");
   delay(1000);
   lcd.clear();
   lcd.write("7");
   delay(1000);
   lcd.clear();
   lcd.write("6");
   delay(1000);
   lcd.clear();
   lcd.write("5");
   delay(1000);
   lcd.clear();
   lcd.write("4");
   delay(1000);
   lcd.clear();
   lcd.write("3");
   delay(1000);
   lcd.clear();
   lcd.write("2");
   delay(1000);
   lcd.clear();
   lcd.write("1");
   delay(1000);
   lcd.clear();
   lcd.write("0");
   delay(1000);
   lcd.clear();
   lcd.write("Success");
   delay(1000);
   lcd.clear();  
 }
 else{}
}
}

septillion

Yeah, of course. But the error DOES contain more info then that. So please post the complete error.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

blh64

#2
Aug 22, 2019, 09:17 pm Last Edit: Aug 22, 2019, 09:18 pm by blh64
First off, it is not an error, it is a warning.  Your variable serialData is of type char yet you are comparing it to a string.  If you want to read in "Activate" then you do it one char at a time and build up your string and then compare that using strcmp().

It might be worthwhile reading this thread to understand how to read the serial port well.

TechGenius866

The rest is just "if(serialData == "Activate")"

TheMemberFormerlyKnownAsAWOL

#4
Aug 22, 2019, 09:52 pm Last Edit: Aug 22, 2019, 09:55 pm by TheMemberFormerlyKnownAsAWOL
Why not just post your code?
(Guessing that serialData is a variable of an integer datatype)

TechGenius866

Why not just post your code?
Umm I did... Or are you talking about just posting the code out of a file? I'll do that.

wildbill

Reread reply #2. Blh64 already nailed the issue for you.

TechGenius866

Ok, can you please explain that in beginner form? LOL  ::)

blh64

Ok, can you please explain that in beginner form? LOL  ::)
You are reading in a single char but trying to compare that to a string "Activate" which is something C/C++ doesn't do.  strings are not an integral type and can't be compared using '=='

TechGenius866

I'm getting there... what do you do instead? Can you please give me some example code?

cattledog

Quote
what do you do instead
There are several ways to approach this. Most simple would be to just send the single letter A instead of the entire word "Activate".

Then use this to test the sent character.

Code: [Select]
if(Serial.available())
  {
    serialData = Serial.read();

    //if(serialData == "Activate") // << Issue
   if(serialData == 'A')
{
 

blh64

I'm getting there... what do you do instead? Can you please give me some example code?
I provided a link in relpy #2.  Click on it. Read it.  It will be very enlightening.

TechGenius866

I provided a link in relpy #2.  Click on it. Read it.  It will be very enlightening.
very enlightening for others, maybe. But I don't really understand it... srry

septillion

Which part didn't you understand?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

TomGeorge

#14
Aug 24, 2019, 01:38 pm Last Edit: Aug 24, 2019, 01:38 pm by TomGeorge
Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What model Arduino are you using?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up