Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI_hw NVIC_set_all_priorities SoftPWM
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:
-
Tx USART TX pin used to connect to Nextion LCD's RX pin Rx USART 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:
-
Color Integer 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:
-
x x coordinate position y y coordinate position r Radius of the circle color Color 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:
-
x1 x coordinate starting position y1 y coordinate starting position x2 x coordinate ending position y2 y coordinate ending position color Color 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:
-
x x position y y position color Color 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:
-
x x coordinate of top-left corner position y y coordinate of top-left corner position w Width of the rectangle h Height of the rectangle color Color 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:
-
x x position. y y position. w Width of string area. h Height of string area. font Font ID to use (0:smallest - 7:largest). fontcolor Color Integer value (0 to 65535) to represent the font color of the string - represented in 16-bit 565 color format. backcolor Color Integer value (0 to 65535) to represent the background color of the string - represented in 16-bit 565 color format. xcenter Horizontal alignment (0: left-aligned, 1: entered, 2: right-aligned). ycenter Vertical alignment (0: upper-aligned, 1: entered, 2: lower-aligned). str String 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:
-
x x coordinate position y y coordinate position r Radius of the circle color Color 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:
-
x x coordinate of top-left corner position y y coordinate of top-left corner position w Width of the rectangle h Height of the rectangle color Color 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:
-
true LCD is being touched. false LCD 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:
-
Integer indicating 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:
-
Integer indicating the X coordinate of the last touch.
Definition at line 58 of file NextionLCD.cpp.
Generated on Sat Jul 23 2022 23:48:08 by
1.7.2