2019-02-27 11:57:45 +08:00
|
|
|
# ボタン
|
|
|
|
|
|
|
|
|
|
## read()
|
|
|
|
|
|
|
|
|
|
**説明:**
|
|
|
|
|
|
|
|
|
|
この関数はボタンの状態を直接読み出します。 1: pressed, 0: released.
|
|
|
|
|
|
|
|
|
|
**構文:**
|
|
|
|
|
|
2019-03-01 18:57:09 +08:00
|
|
|
<mark>uint8_t read();</mark>
|
2019-02-27 11:57:45 +08:00
|
|
|
|
|
|
|
|
**使用例:**
|
|
|
|
|
|
|
|
|
|
```arduino
|
|
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
M5.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
M5.Lcd.setCursor(0, 0);
|
|
|
|
|
M5.Lcd.print("Button A Status: ");
|
|
|
|
|
M5.Lcd.println(M5.BtnA.read());
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## isPressed()
|
|
|
|
|
|
|
|
|
|
**説明:**
|
|
|
|
|
|
|
|
|
|
この関数は最後にM5.Button.read()を呼び出した時のボタンの状態を読み出します。1: pressed, 0: released.
|
|
|
|
|
|
|
|
|
|
**構文:**
|
|
|
|
|
|
2019-03-01 18:57:09 +08:00
|
|
|
<mark>uint8_t isPressed();</mark>
|
2019-02-27 11:57:45 +08:00
|
|
|
|
|
|
|
|
**使用例:**
|
|
|
|
|
|
|
|
|
|
```arduino
|
|
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
M5.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
M5.update(); // update()を呼び出す必要があります。
|
|
|
|
|
M5.Lcd.setCursor(0, 0);
|
|
|
|
|
if (M5.BtnA.isPressed()) {
|
|
|
|
|
M5.Lcd.printf("A button is pressed.");
|
|
|
|
|
} else {
|
|
|
|
|
M5.Lcd.printf("A button is released.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## wasPressed()
|
|
|
|
|
|
|
|
|
|
**構文:**
|
|
|
|
|
|
2019-03-01 18:57:09 +08:00
|
|
|
<mark>uint8_t wasPressed();</mark>
|
2019-02-27 11:57:45 +08:00
|
|
|
|
|
|
|
|
**説明:**
|
|
|
|
|
|
|
|
|
|
この関数はボタンが押される度に一度だけ1を返します。 1: pressed, 0: released.
|
|
|
|
|
|
|
|
|
|
**使用例:**
|
|
|
|
|
|
|
|
|
|
```arduino
|
|
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
M5.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
M5.update();
|
|
|
|
|
M5.Lcd.clear();
|
|
|
|
|
M5.Lcd.setCursor(0, 0);
|
|
|
|
|
if (M5.BtnA.wasPressed()) {
|
|
|
|
|
M5.Lcd.printf("Button A was pressed.");
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## pressedFor()
|
|
|
|
|
|
|
|
|
|
**構文:**
|
|
|
|
|
|
2019-03-01 18:57:09 +08:00
|
|
|
<mark>uint8_t pressedFor(uint32_t ms);</mark>
|
2019-02-27 11:57:45 +08:00
|
|
|
|
|
|
|
|
**説明:**
|
|
|
|
|
|
|
|
|
|
この関数は引数で指定した時間以上ボタンが押し続けられたら1を返します。 1: pressed, 0: released.
|
|
|
|
|
|
|
|
|
|
| argument | 説明 | type |
|
|
|
|
|
| --- | --- | -- |
|
|
|
|
|
| ms | pressing time (ms) | uint32_t |
|
|
|
|
|
|
|
|
|
|
**使用例:**
|
|
|
|
|
|
|
|
|
|
```arduino
|
|
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
M5.begin();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
M5.update();
|
|
|
|
|
M5.Lcd.clear();
|
|
|
|
|
M5.Lcd.setCursor(0, 0);
|
|
|
|
|
if (M5.BtnA.pressedFor(2000)) {
|
|
|
|
|
M5.Lcd.printf("Button A was pressed for more than 2 seconds.");
|
|
|
|
|
delay(1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|