Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Using the LCD

mob41 edited this page Jan 16, 2017 · 10 revisions

The library provides an LCDGraphics class to deal with the LCD. The LCDGraphics class is currently experimental. How "experimental" is it? Let's see:

expImg

The FakeVirtualLCD shows the original image rendered by the LCDGraphics's internal BufferedImage. The VirtualLCD shows the image rendered (to a ev3dev-compatible pixel byte array) by the LCDGraphics.

Bug:

  • Fix rendering strings
  • Fix Black-White color conversion
  • Fix images

Usage

If you know how to use with Graphics2D, you are in the right way with LCDGraphics. LCDGraphics is just a implementation of Graphics2D. If possible, you can even hook it to other graphics libraries (i think...)

LCD lcd = new LCD(); //Creates an ev3dev LCD instance.

LCDGraphics g = new LCDGraphics(lcd); //Creates the LCDGraphics class

//Although you are able to set colors other than BLACK and WHITE,
//the result is only BLACK and WHITE, and if there will be problems
//if color images are specified.
g.setColor(Color.BLACK);
g.drawLine(0, 0, 100, 30); //Draws a line from (0,0) to (100,30)
g.fillRect(50, 50, 25, 25); //Draws a 25x25 rectangle at (50,50)

g.flush(); //Applies the graphics to the LCD

VirtualLCD for development

The library provides a VirtualLCD to emulate the graphics on the computer before the ev3.

VirtualLCD lcd = new VirtualLCD();
lcd.showVLCD(); //Shows an UI of the virtual LCD

LCDGraphics g = new LCDGraphics(lcd);
g.setBlackColor(); //Alternative
g.drawLine(0, 0, 100, 30); //Draws a line from (0,0) to (100,30)
g.drawRect(50, 50, 50, 50); //Draws a 50x50 rectangle at (50,50)
g.flush(); //Applies the graphics to the LCD

It should be like this:

ev3virtuallcd_image

Advanced

The library also allows you to draw directly to the buffer. More details please refer to http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/

LCD lcd = new LCD();

final int SCREEN_WIDTH = 178;
final int SCREEN_HEIGHT = 128;
final int LEN = 24;
final int SIZE = 3072;
byte[] arr = new byte[SIZE];

//0xff (1) = BLACK
//0x00 (0) = WHITE

//Draws a horizontal line to row 5 to the end of the screen
for (int i = 0; i < SCREEN_WIDTH; i++){
    arr[5 * LEN + i] = (byte) 0xff; //Fill with BLACK
}

lcd.draw(arr);

Development stage of LCDGraphics

The LCDGraphics class is still experimental.

  • Lots of bugs... XD

Clone this wiki locally