9 years, 5 months ago.

problem with lcd? it wont clear properly the screen? below is my coding

#include "mbed.h"
#include "TextLCD.h"


AnalogIn LM35(p15);
TextLCD lcd (p21,p22,p23,p24,p25,p26);// rs, e, d4-d7
DigitalIn PIR (p19);
DigitalOut myled (LED1);
DigitalOut myled2 (LED2);



int main()              
{
    int i = 0;
    float tempC;
    while(1)
    {
        lcd.locate(0,0);
        lcd.printf("welcome");
        wait(0.5);//wait for 0.5s for the system, to detect
        lcd.cls();
        wait(0.5);
     if (PIR==1)
     {
        tempC=LM35.read()*330;
        wait(0.2);
        lcd.cls();
        wait(0.45);
        lcd.locate(0,0);
        lcd.printf("temperature:");
        lcd.locate(1,1);
        lcd.printf("%.2f deg",tempC);
       
        if(tempC>25)
        {
            myled=1;
            myled2=0;
        }
        else
        {
            myled2=1;
            myled=0;
        }
                       
      }
      if(PIR==0)
      {
       lcd.printf("no motion");
       lcd.cls();
    
      }

}
}

1 Answer

9 years, 5 months ago.

Please use <<code>> and <</code>> tags around your code when posting to keep it readable.

What do you mean by "wont clear properly". What exactly do you see on the display. You call lcd.cls() several times. Where does it fail?

Note that:

 if (PIR==0) { 
   lcd.printf("no motion");
   lcd.cls();
}

will print "no motion" and immediately clear the text again.

Note that cls() is a slow function and the display you use may need more time to complete it.

Accepted Answer

yeah i do do several call for the lcd.cls() but the welcome sign wont goes off on my lcd screen. It will remain with my temperature text.

posted by KENJI LEE 11 Dec 2014

Currently when (PIR==1) you will clear the screen, show 'temperature' in top line, show degrees in second line. Then you repeat the while loop, locate cursor to top line and print welcome on top line. The degrees remains on second line while you wait for .5s before clearing screen again.

Change code to:

    while(1)
    {
        lcd.cls();
        lcd.printf("welcome");
etc..
posted by Wim Huiskamp 11 Dec 2014