pdf-icon

Arduino入門

2. デバイス&サンプル

LGFX_Buttonについて

Adafruit GFX LibraryのAdafruit_GFX_Buttonとの互換性を取るためのクラスです。 画面上に仮想的なボタンを配置して簡単に制御できるようになります。

使い方

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

指定した座標がボタンの位置に含まれるかどうかを判定します。タッチパネルでボタンが押されたかどうかの判断に利用します。

Syntax:

bool contains(int16_t x, int16_t y)

Parameter Type 説明
x int16_t 判定するX座標
y int16_t 判定するY座標

drawButton

ボタンを描画します。引数のinvertedをtrueにすると背景色が反転します。

Syntax:

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

Parameter Type 説明
inverted bool ボタンの文字色と背景色を反転させるかどうか
long_name const char* 設定するとラベルの文字列を変更します。

initButton

ボタンを初期状態を設定します。

void initButton()

isPressed

press()で設定したボタンの状態を返却します。

justPressed

ボタンが押されたかどうか判定します。

Syntax:

bool justPressed()

justReleased

ボタンを離したかどうか判定します。

Syntax:

bool justReleased()

press

ボタンの状態を設定します。

Syntax:

void press(bool p)

Parameter Type 説明
p bool ボタンの状態を設定します。

setLabelDatum

ラベルの基準点(datum)を設定します。

Syntax:

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

Parameter Type 説明
x_delta int16_t ボタンの状態を設定します。
y_delta int16_t ボタンの状態を設定します。
datum textdatum_t 基準点(datum)(*1)を設定します。

*1.テキストの基準点(datum)について

On This Page