Newer
Older
M5StickCPlus_FactoryTest2022 / SampleSrc / button01.ino
@motoki miura motoki miura on 6 Apr 2023 1005 bytes use display
#include <M5StickCPlus.h>
#define USE_DISPLAY true

void setup() {
  M5.begin(115200);
  M5.Lcd.setRotation(3);
  displayMessage("Press any key and Release.");
}

void loop() {
  M5.update(); // 各ボタンの状態を(読み取って)更新する:ボタンを判定するときは必須。
  
  if (M5.BtnA.wasReleasefor(1000) ) {
    displayMessage("[A] was Pressed longer than 1s");
  } else if (M5.BtnA.wasReleased()) {
    displayMessage("[A] was Pressed");
  } else if (M5.BtnB.wasReleasefor(1000) ) {
    displayMessage("[B] was Pressed longer than 1s");
  } else if (M5.BtnB.wasReleased()) {
    displayMessage("[B] was Pressed");
  } else if (M5.Axp.GetBtnPress() == 2) {
    displayMessage("[Power] was Pressed");
  }
  
  delay(10);
}

void displayMessage(const char* mes){
  Serial.println(mes);
  
  #if USE_DISPLAY
  M5.Lcd.fillScreen( ORANGE );
  M5.Lcd.setCursor(0, 0, 2);
  M5.Lcd.setTextSize(2);
  M5.Lcd.setTextColor( WHITE, OLIVE );
  M5.Lcd.printf(" %s ",  mes);
  #endif
}