pdf-icon

Display

RGB565 Color

The following API uses the RGB565 color coding format

#define BLACK       0x0000 /*   0,   0,   0 */
#define NAVY        0x000F /*   0,   0, 128 */
#define DARKGREEN   0x03E0 /*   0, 128,   0 */
#define DARKCYAN    0x03EF /*   0, 128, 128 */
#define MAROON      0x7800 /* 128,   0,   0 */
#define PURPLE      0x780F /* 128,   0, 128 */
#define OLIVE       0x7BE0 /* 128, 128,   0 */
#define LIGHTGREY   0xC618 /* 192, 192, 192 */
#define DARKGREY    0x7BEF /* 128, 128, 128 */
#define BLUE        0x001F /*   0,   0, 255 */
#define GREEN       0x07E0 /*   0, 255,   0 */
#define CYAN        0x07FF /*   0, 255, 255 */
#define RED         0xF800 /* 255,   0,   0 */
#define MAGENTA     0xF81F /* 255,   0, 255 */
#define YELLOW      0xFFE0 /* 255, 255,   0 */
#define WHITE       0xFFFF /* 255, 255, 255 */
#define ORANGE      0xFDA0 /* 255, 180,   0 */
#define GREENYELLOW 0xB7E0 /* 180, 255,   0 */
#define PINK        0xFC9F /* 255, 255,  16 */

fillScreen

Syntax:

void fillScreen(uint32_t color);

Description:

  • Fill the entire screen with the specified color

Parameters:

  • uint32_t color:
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.fillScreen(BLUE);
}
void loop() {}

setTextColor

Syntax:

void setTextColor(uint16_t color, uint16_t backgroundcolor);

Description:

  • Sets the foreground color and background color of the displayed text.

Parameters:

  • uint16_t color:
    • The foreground color of the text
  • uint16_t backgroundcolor:
    • Background color of the text

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.setTextColor(RED, WHITE);
  M5.Lcd.println("Hello, M5Stack world!!");
}
void loop() {
}

print

Syntax:

size_t print(const String &s);

Description:

Starts printing text at the current cursor position on the screen

Parameters:

  • const String &s:
    • string

Return:

  • size_t:
    • Length of printed text

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.print("print text");
}
void loop() {}

setCursor

Syntax:

void setCursor(int16_t x0, int16_t y0);

Description:

  • Move the cursor position to (x0, y0).

Parameters:

  • int16_t x0:
    • point x
  • int16_t y0:
    • point y

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.setCursor(7, 20);
  M5.Lcd.println("scan done");
  M5.Lcd.setCursor(5, 60);
  M5.Lcd.printf("50 AP");
}
void loop(){}

drawPixel

Syntax:

void drawPixel(int16_t x, int16_t y, uint16_t color);

Description:

  • Draw pixels at position (x,y)

Parameters:

  • int16_t x:
    • x position
  • int16_t y:
    • y position
  • uint16_t color:
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.drawPixel(22, 22, RED);
}
void loop() {}

drawLine

Syntax:

void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);

Description:

  • Draws a line from point (x0,y0) to point (x1,y1) in the specified color.

Parameters:

  • int16_t x0:
    • point x0
  • int16_t y0:
    • point y0
  • int16_t x1:
    • point x1
  • int16_t y1:
    • point y1
  • uint16_t color
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.drawLine(0, 0, 12, 12, BLUE);
}
void loop() {}

drawTriangle

Syntax:

void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);

Description:

  • Draw triangles in the specified colors with vertices (x0,y0), (x1,y1) and (x2,y2).

Parameters:

  • int16_t x0:
    • triangle x0
  • int16_t y0:
    • triangle y0
  • int16_t x1:
    • triangle x1
  • int16_t y1:
    • triangle y1
  • int16_t x2:
    • triangle x2
  • int16_t y2:
    • triangle y2
  • uint16_t color
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.drawTriangle(22, 22, 69, 98, 51, 22, RED);
}
void loop() {}

fillTriangle

Syntax:

void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);

Description:

  • Draw filled triangles in the specified colors with vertices (x0,y0), (x1,y1) and (x2,y2).

Parameters:

  • int16_t x0:
    • triangle x0
  • int16_t y0:
    • triangle y0
  • int16_t x1:
    • triangle x1
  • int16_t y1:
    • triangle y1
  • int16_t x2:
    • triangle x2
  • int16_t y2:
    • triangle y2
  • uint16_t color
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.fillTriangle(22, 22, 69, 98, 51, 22, RED);
}
void loop() {}

drawRect

Syntax:

void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);

Description:

  • Draw a rectangle in the specified color, where the coordinates of the upper left corner of the rectangle (x, y), width and height are width and height respectively

Parameters:

  • int16_t x:
    • x-coordinate of the upper left corner of the rectangle
  • int16_t y:
    • y-coordinate of the upper left corner of the rectangle
  • int16_t w:
    • Rectangular width(px)
  • int16_t h:
    • Rectangular height(px)
  • uint16_t color:
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.drawRect(50, 100, 30, 10, BLUE);
}
void loop() {}

fillRect

Description:

  • Draws a `filled' rectangle in the specified color, with the coordinates of the upper-left corner as (x,y) and the width and height as width and height, respectively.

Syntax:

void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);

Parameters:

  • int16_t x:
    • x-coordinate of the upper left corner of the rectangle
  • int16_t y:
    • y-coordinate of the upper left corner of the rectangle
  • int16_t w:
    • Rectangular width(px)
  • int16_t h:
    • Rectangular height(px)
  • uint16_t color:
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.fillRect(50, 100, 20, 10, BLUE);
}
void loop() {}

drawRoundRect

Syntax:

void drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);

Description:

  • Draw a rectangle with rounded corners in the specified color, where the upper-left corner of the rectangle has the coordinates (x,y), the width and height are width and height respectively, and the radius of the rounded corners is radius.

Parameters:

  • int16_t x:
    • x-coordinate of the upper left corner of the rectangle
  • int16_t y:
    • y-coordinate of the upper left corner of the rectangle
  • int16_t w:
    • Rectangular width(px)
  • int16_t h:
    • Rectangular height(px)
  • int16_t radius:
    • radius of a rounded corner
  • uint16_t color:
    • color value

Return:

  • null

Example:

#include <M5StickC.h>

void setup() {
  M5.begin();
  M5.Lcd.fillRoundRect(40, 70, 20, 10, 4, BLUE);
}
void loop() {}
On This Page