pdf-icon

Arduino入門

2. デバイス&サンプル

6. アプリケーション

Chain DualKey Switch

Chain DualKey のスイッチに関する API とサンプルプログラムです。

サンプルプログラム

ビルド要件

  • M5Stack ボードマネージャーのバージョン ≥ 3.2.4
  • 開発ボードの設定 = M5ChainDualKey
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#define SWITCH_BLE  8
#define SWITCH_WIFI 7

void setup() {
  pinMode(SWITCH_BLE,  INPUT);
  pinMode(SWITCH_WIFI, INPUT);

  Serial.begin(115200);
}

void loop() {
  if (digitalRead(SWITCH_BLE) == HIGH) {
    Serial.println("Switch in BLE position");
  } else if (digitalRead(SWITCH_WIFI) == HIGH) {
    Serial.println("Switch in WIFI position");
  } else {
    Serial.println("Switch in middle position");
  }

  delay(500);
}

本プログラムは、500 ミリ秒ごとにスイッチの位置を検出し、その状態を Serial Monitor に出力します。

On This Page