Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

M5stack CoreInkを使ってみる その2:側面のダイヤルを使ったりカーソルを整えたりする

shuzo-kino.hateblo.jp
の続き

実際のところ

スクリプト

右側面にあるダイヤルは、

  • 押し込むとG38
  • 上方向がG37
  • 下方向がG39

と割り当てられているので、それに対応する。

ついでに、前回のままではボタンを押すたび下にいってたのでカーソル位置をリセットするようにした。

#include <M5Unified.h>

void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);

  M5.Display.setTextSize(2);
  M5.Display.println("Hello M5Stack!");
  M5.Display.println("Using M5Unified");
  M5.Display.display();
}

void loop() {
  M5.update();

  if (M5.BtnPWR.wasClicked()) {
    M5.Display.clear();
    M5.Display.setCursor(10, 10);  // Set cursor to (10, 10)
    M5.Display.println("Power button clicked!");
    M5.Display.display();
  }

  if (M5.BtnEXT.wasClicked()) {
    M5.Display.clear();
    M5.Display.setCursor(10, 10);  // Set cursor to (10, 10)
    M5.Display.println("EXT button clicked!");
    M5.Display.display();
  }

  // Add logic for dial buttons
  if (digitalRead(37) == LOW) {
    M5.Display.clear();
    M5.Display.setCursor(10, 10);  // Set cursor to (10, 10)
    M5.Display.println("Dial button 1 pressed!");
    M5.Display.display();
    delay(200); // Debounce delay
  }

  if (digitalRead(38) == LOW) {
    M5.Display.clear();
    M5.Display.setCursor(10, 10);  // Set cursor to (10, 10)
    M5.Display.println("Dial button 2 pressed!");
    M5.Display.display();
    delay(200); // Debounce delay
  }

  if (digitalRead(39) == LOW) {
    M5.Display.clear();
    M5.Display.setCursor(10, 10);  // Set cursor to (10, 10)
    M5.Display.println("Dial button 3 pressed!");
    M5.Display.display();
    delay(200); // Debounce delay
  }

  delay(100);
}