pdf-icon

Arduino Quick Start

About LGFX_Button

This class is designed to be compatible with Adafruit GFX Library.Virtual buttons can be placed on the screen for easy control.

Usage

Define and use LGFX_Button.

LGFX_Button button();

Example:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>
static int32_t w;
static int32_t h;
LGFX_Button button;
void setup(void)
{
auto cfg = M5.config();
M5.begin(cfg);
w = M5.Lcd.width();
h = M5.Lcd.height();
button.initButton(&M5.Lcd, w / 2 , h / 2, 100, 50, TFT_RED, TFT_YELLOW, TFT_BLACK, "Btn" );
button.drawButton();
}
void loop(void)
{
M5.update();
if (M5.BtnA.isPressed()) {
button.press(true);
button.drawButton(true);
M5.Lcd.drawString("Button Pressed ", 0, 0, &fonts::lgfxJapanGothic_16);
Serial.println("Pressed");
} else {
button.press(false);
button.drawButton(false, "Test");
M5.Lcd.drawString("Button Released", 0, 0, &fonts::lgfxJapanGothic_16);
Serial.println("Released");
}
delay(50);
}

API

contains

Determines if the specified coordinates are included in the button position. Used to determine if a button is pressed on the touch panel.

Syntax:

bool contains(int16_t x, int16_t y)

Parameter Type Description
x int16_t point x
y int16_t point y

drawButton

Draws a button. If the inverted argument is set to true, the background color is inverted.

Syntax:

void drawButton(bool inverted = false, const char* long_name = nullptr)

Parameter Type Description
inverted bool Whether to invert the text and background colors of buttons.
long_name const char* Change the label to the string set.

initButton

Initialize the button.

void initButton(M5GFX *gfx, int16_t x, int16_t y, int16_t w, int16_t h, const T& outline, const T& fill, const T& textcolor, const char* label, float textsize_x = 1.0f, float textsize_y = 1.0f)

Parameter Type Description
gfx M5GFX* Panel or M5Canvas
x int16_t Point x
y int16_t Point y
w int16_t Width
h int16_t Height
outline const T& Color of outline(*1)
fill const T& Color of background(*1)
textcolor const T& Color of text(*1)
label const char* Label text
textsize_x float Scale of text x
textsize_y float Scale of text y

*1.About ColorCode

isPressed

Returns the value set by press().

justPressed

Determine if a button is pressed.

Syntax:

bool justPressed()

justReleased

Determine if a button is released.

Syntax:

bool justReleased()

press

Set the button status.

Syntax:

void press(bool p)

Parameter Type Description
p bool Status of button

setLabelDatum

Set the label datum..

Syntax:

void setLabelDatum(int16_t x_delta, int16_t y_delta, textdatum_t datum = middle_center)

Parameter Type 説明
x_delta int16_t Delta x
y_delta int16_t Delta y
datum textdatum_t Datum(*1)

*1.About TextDatum

On This Page