LCD Clear

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

LCD Clear

Postby NadirHajiyev » Thu Jul 12, 2012 8:59 am

Hello. I tried write a program to display current voltage of battery.
But when I run it in brick screen is not cleaned. Could you help me to fix this error?
Here is my code. Thanks a lot.
Code: Select all
import javax.microedition.lcdui.Graphics;

import lejos.nxt.Battery;
import lejos.nxt.Button;
import lejos.nxt.LCD;
public class GetVoltByGUI {
   public static void main(String[] args){
      
      Graphics g = new Graphics();
      final int lcdWidth = LCD.SCREEN_WIDTH;
      final int lcdHeight = LCD.SCREEN_HEIGHT;
      
      while(!Button.ESCAPE.isPressed()){
         while(!Button.ENTER.isPressed()){
            g.drawString("Do you want", lcdWidth/2, lcdHeight/4, Graphics.HCENTER|Graphics.BASELINE);
            g.drawString("to see voltage of", lcdWidth/2, lcdHeight/4+8, Graphics.HCENTER|Graphics.BASELINE);
            g.drawString("batery?", lcdWidth/2, lcdHeight/4+16, Graphics.HCENTER|Graphics.BASELINE);
         }
         LCD.clearDisplay();
         if(Button.ENTER.isPressed()){
            g.drawString(String.valueOf((Battery.getVoltageMilliVolt())), lcdWidth/2, lcdHeight/4, Graphics.HCENTER|Graphics.BASELINE);
         }
      }
      
   }
}
NadirHajiyev
New User
 
Posts: 20
Joined: Thu Jul 05, 2012 10:25 am

Re: LCD Clear

Postby gloomyandy » Thu Jul 12, 2012 4:44 pm

What exactly do you expect to happen and what exactly happens. It is unlikely that anyone will actually test your code to see what happens, so it will help people to help you if you describe how you want the code to work and what it is actually doing. So when you say the displayed is not cleared what do you mean what remains on the screen and when?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4084
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: LCD Clear

Postby NadirHajiyev » Fri Jul 13, 2012 8:06 am

Thanks.
I solve this problem by adding
Code: Select all
Thread.sleep();
to my code.
Next time I`ll do my best to describe my question.
The problem was that:
first the question (do you want to...) is displayed and when "enter" is pressed first clear display then it shows current battery voltage.
But in practice the display is not clear.
NadirHajiyev
New User
 
Posts: 20
Joined: Thu Jul 05, 2012 10:25 am

Re: LCD Clear

Postby matthias » Fri Jul 13, 2012 8:54 am

you also might want to put the 3 drawString calls before the while loop. (you are writing the same text to the display over and over again, as long as no button is pressed...)
Code: Select all
        g.drawString("Do you want", lcdWidth/2, lcdHeight/4, Graphics.HCENTER|Graphics.BASELINE);
        g.drawString("to see voltage of", lcdWidth/2, lcdHeight/4+8, Graphics.HCENTER|Graphics.BASELINE);
        g.drawString("batery?", lcdWidth/2, lcdHeight/4+16, Graphics.HCENTER|Graphics.BASELINE);
        while(!Button.ENTER.isPressed());

Also: why dont you use the LCD.drawString method instead of the Graphics.drawString method?
matthias
New User
 
Posts: 20
Joined: Thu Mar 22, 2012 11:44 am


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 1 guest

more stuff