yacine sidhoum / Mbed 2 deprecated mbed_motor_dc_driver_nextion_nx8048t050_011_2019_v0008

Dependencies:   mbed QEI_hw NVIC_set_all_priorities SoftPWM

Embed: (wiki syntax)

« Back to documentation index

NextionLCD Class Reference

NextionLCD Class Reference

Class library for a Nextion graphics LCD to provide basic graphics and touch functions. More...

#include <NextionLCD.h>

Public Member Functions

 NextionLCD (PinName Tx, PinName Rx)
 Create a NextionLCD object for a graphics LCD connected to the specified pins.
void ClrScr (uint16_t color)
 Clears the lcd by filling it with the specified color pixels.
void DrawString (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t font, uint16_t fontcolor, uint16_t backcolor, uint8_t xcenter, uint8_t ycenter, char *str)
 Draws a string on the lcd at the specified xy position.
void DrawPixel (uint16_t x, uint16_t y, uint16_t color)
 Draws a pixel on the lcd at the specified xy position.
void DrawLine (uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
 Draws a line on the lcd from x1,y1 to x2,y2.
void DrawRectangle (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 Draws a rectangle on the lcd from x,y with width w and height h.
void FillRectangle (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
 Draws a filled rectangle on the lcd from x,y with width w and height h.
void DrawCircle (uint16_t x, uint16_t y, uint16_t r, uint16_t color)
 Draws a circle on the lcd at x,y with a radius of r.
void FillCircle (uint16_t x, uint16_t y, uint16_t r, uint16_t color)
 Draws a filled circle on the lcd at x,y with a radius of r.
bool Touch (void)
 Determines if the touchscreen is being touched or not.
int TouchX (void)
 Get the X coordinate of the last touch on the touchscreen.
int TouchY (void)
 Get the Y coordinate of the last touch on the touchscreen.

Detailed Description

Class library for a Nextion graphics LCD to provide basic graphics and touch functions.

This library DOES NOT provide the HMI functionality that is included with Nextion LCDs.

Example:

 #include "mbed.h"
 #include "NextionLCD.h"

 NextionLCD lcd(PB_6, PB_7);     //Tx, Rx
 
 int main() 
 {
     char str[20];
     
     lcd.ClrScr(BLACK);  //clear the display and fill it with BLACK pixels
     
     //draw some shapes
     lcd.FillCircle(100,100,50,RED);
     lcd.DrawPixel(100,100,WHITE);
     lcd.DrawRectangle(50,50,100,100,BLUE);
     lcd.DrawLine(50,50,100,150,YELLOW);
 
     while(1) 
     {
         if (lcd.Touch())        //test if the lcd was touched
         {
             sprintf(str, "Touched: %d,%d", lcd.TouchX(), lcd.TouchY()); //print to string buffer
             lcd.DrawString(0,0,200,30,0,GREEN,GRAY,0,0,str);            //display string on LCD:
                                                                         // x,y          : 0,0
                                                                         // width, height: 200, 300
                                                                         // font         : 0
                                                                         // fontcolor    : GREEN
                                                                         // backcolor    : GRAY
                                                                         // x alignment  : 0 (left)
                                                                         // y alignment  : 0 (top)
         }
         else
         {
             lcd.DrawString(0,0,200,30,0,BLACK,BLACK,0,0,"");            //blank display area when not touched
         }
     }
 }

Definition at line 85 of file NextionLCD.h.


Constructor & Destructor Documentation

NextionLCD ( PinName  Tx,
PinName  Rx 
)

Create a NextionLCD object for a graphics LCD connected to the specified pins.

Parameters:
TxUSART TX pin used to connect to Nextion LCD's RX pin
RxUSART RX pin used to connect to Nextion LCD's TX pin

Definition at line 7 of file NextionLCD.cpp.


Member Function Documentation

void ClrScr ( uint16_t  color )

Clears the lcd by filling it with the specified color pixels.

Parameters:
ColorInteger value (0 to 65535) to represent the color to fill the screen with - represented in 16-bit 565 color format

Definition at line 18 of file NextionLCD.cpp.

void DrawCircle ( uint16_t  x,
uint16_t  y,
uint16_t  r,
uint16_t  color 
)

Draws a circle on the lcd at x,y with a radius of r.

Parameters:
xx coordinate position
yy coordinate position
rRadius of the circle
colorColor of the circle (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 42 of file NextionLCD.cpp.

void DrawLine ( uint16_t  x1,
uint16_t  y1,
uint16_t  x2,
uint16_t  y2,
uint16_t  color 
)

Draws a line on the lcd from x1,y1 to x2,y2.

Parameters:
x1x coordinate starting position
y1y coordinate starting position
x2x coordinate ending position
y2y coordinate ending position
colorColor of the line (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 30 of file NextionLCD.cpp.

void DrawPixel ( uint16_t  x,
uint16_t  y,
uint16_t  color 
)

Draws a pixel on the lcd at the specified xy position.

Parameters:
xx position
yy position
colorColor of the pixel (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 26 of file NextionLCD.cpp.

void DrawRectangle ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draws a rectangle on the lcd from x,y with width w and height h.

Parameters:
xx coordinate of top-left corner position
yy coordinate of top-left corner position
wWidth of the rectangle
hHeight of the rectangle
colorColor of the rectangle (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 34 of file NextionLCD.cpp.

void DrawString ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint8_t  font,
uint16_t  fontcolor,
uint16_t  backcolor,
uint8_t  xcenter,
uint8_t  ycenter,
char *  str 
)

Draws a string on the lcd at the specified xy position.

Parameters:
xx position.
yy position.
wWidth of string area.
hHeight of string area.
fontFont ID to use (0:smallest - 7:largest).
fontcolorColor Integer value (0 to 65535) to represent the font color of the string - represented in 16-bit 565 color format.
backcolorColor Integer value (0 to 65535) to represent the background color of the string - represented in 16-bit 565 color format.
xcenterHorizontal alignment (0: left-aligned, 1: entered, 2: right-aligned).
ycenterVertical alignment (0: upper-aligned, 1: entered, 2: lower-aligned).
strString content.

Definition at line 22 of file NextionLCD.cpp.

void FillCircle ( uint16_t  x,
uint16_t  y,
uint16_t  r,
uint16_t  color 
)

Draws a filled circle on the lcd at x,y with a radius of r.

Parameters:
xx coordinate position
yy coordinate position
rRadius of the circle
colorColor of the circle (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 46 of file NextionLCD.cpp.

void FillRectangle ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draws a filled rectangle on the lcd from x,y with width w and height h.

Parameters:
xx coordinate of top-left corner position
yy coordinate of top-left corner position
wWidth of the rectangle
hHeight of the rectangle
colorColor of the rectangle (0 to 65535) - represented in 16-bit 565 color format.

Definition at line 38 of file NextionLCD.cpp.

bool Touch ( void   )

Determines if the touchscreen is being touched or not.

Return values:
trueLCD is being touched.
falseLCD is not being touched.

Definition at line 50 of file NextionLCD.cpp.

int TouchX ( void   )

Get the X coordinate of the last touch on the touchscreen.

Return values:
Integerindicating the X coordinate of the last touch.

Definition at line 54 of file NextionLCD.cpp.

int TouchY ( void   )

Get the Y coordinate of the last touch on the touchscreen.

Return values:
Integerindicating the X coordinate of the last touch.

Definition at line 58 of file NextionLCD.cpp.