Pages: [1]   Go Down
Author Topic: Problem to erase LCD Screen afer displayed message  (Read 576 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

For a few hours, I'm faced a problem with the LCD screen (LiquidCrystal).

I must, with a socket, send messages and display on the LCD Screen. The problem is that messages are displayed side by side but I would like they are erased for display another messages.

I search so to clear the LCD screen between each messages.

Here is my code (the comments are all my test) :
Code:
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0x02, 0xC7 };
IPAddress ip(192, 168, 1, 17);
//IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 255, 0);


EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  Ethernet.begin(mac, ip, subnet);
  server.begin();
   lcd.clear();
  Serial.begin(9600);
  lcd.begin(16, 2);
}
void loop() {
  //wait for a new client:
int in=0,i;char message[16] = "";
  EthernetClient client = server.available();
  char thisChar;
 
  // when the client sends the first byte, say hello:
 /* if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();   
     //lcd.print("We have a new client");

      alreadyConnected = true;
     
    } */
  //i=0;
 
    if (client.available() > 0) {
      //in=1;
 
       thisChar = client.read();
       lcd.print(thisChar);
       delay(300);
       lcd.clear();
     
      /* server.write(thisChar);   
      message[i]=thisChar;
      i++;
      Serial.print("i");
      Serial.println(i);
      //delay(300);
     
      //sprintf(message, "%c", thisChar);
      Serial.print("message");
      Serial.println(message);
     
    }*/
    if(i!=0) message[i]=0;
    if (in==1){
      delay(3000);
      lcd.setCursor(1,0);
    in=0;
  }
}

}

Thanks you in advance for your help.

Cordialy,

(Sorry if my english isn't very good, i'm french).
 
« Last Edit: December 12, 2012, 03:31:14 am by Catskan » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


use lcd.clear() to clear the screen where you want. If that does not work for your particular screen you might consider printing spaces to remove existing text.

And your English is good enough to describe your problem.

(please use CTRL-T before posting code to auto format the layout of the code -> makes it more readable)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

The problem is "lcd.clear()" erase totaly of screen. We havn't Time read the message.
But when I set a delay, the LCD screen display the message character by character ( I send a string ).

That's to say, he displays a first letter, The LCD is erased And he display the second letter And thus on.

(When use CTRL-T, i's opens a new tab ).

PS : I modified the code, when instructions is in a "setup" function, nothing display on LCD.
« Last Edit: December 12, 2012, 03:25:21 am by Catskan » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just noticed, you clear the screen before you define how big it is ...
Code:
void setup() {
  Ethernet.begin(mac, ip, subnet);
  server.begin();
   lcd.clear();
  Serial.begin(9600);
  lcd.begin(16, 2);
}
better swap those lines?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 26
Posts: 4119
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
just noticed, you clear the screen before you define how big it is ...
They must be copying this from somewhere - it's the third time I've seen it this week.

It is also totally unnecessary at this point since clearing the screen is part of the initialization routine that is handled by the library.


Quote
better swap those lines?
Just leave it out.

Don
Logged

Pages: [1]   Go Up
Jump to: