LCD.clear(); doesn't work

Hello,

The code I made reads from my computer’s Serial port. There are 3 different commands that my computer can send to the arduino:

  1. “DENYALLACCESS”
  2. “CLEAR”
  3. or another string value (personalized message), eg “Hello”

The first one shows “> Access Denied <” on the LCD.
The second one clears the LCD.
The third just displays the given text on the LCD.

Here is my code:

1: String SerialData = "";
2:  
3: void loop(){
4:   SerialData = "";
5:   while(Serial.available()){
6:     SerialData.concat((char)Serial.read());
7:   }
8:   if(SerialData == "DENYALLACCESS"){
9:     LCD.clear();
10:     LCD.setCursor(1, 1);
11:     LCD.print("> Access  Denied <");
12:   }else if(SerialData == "CLEAR"){
13:    LCD.clear();
14:   }else{
15:    LCD.clear();
16:    ProcessStringsFromPC(SerialData);
17:   }
18: }

I have one problem though: although line 13 clears the LCD, the LCD isn’t cleared on lines 9 or 15. Please help!

I have one problem though: although line 13 clears the LCD, the LCD isn't cleared on lines 9 or 15. Please help!

If the method works in one place, it works in all places. Something happens after the clear that makes you think it doesn't work. Since we can't see what you see, and you didn't describe what you see, we can't help you.

One thing to keep in mind is that serial data arrives ssslllooowwwlllyyy. You assume that an entire packet will arrive all at once.

I did LCD.clear(); , then used the string instead of doing it all at once.

Thanks for helping anyways

I did LCD.clear(); , then used the string instead of doing it all at once.

I don't see any strings (NULL terminated array of char) in your code. I only see a String, which is not the same thing.

I don't see anything in this statement that describes what you see on the LCD.

I don't see anything in this statement that describes what you are doing about the fact that serial data arrives slowly, and you are expecting that the entire packet will arrive at once.