Newer
Older
m5scp2_exp / Sample / Sample.ino
@motoki miura motoki miura 2 days ago 1 KB sample
#include <M5Unified.h>

void changeBackgroundColor() {
  // ランダムな背景色を生成
  uint16_t randomColor = random(0x0000, 0xFFFF);  // RGB565形式でランダム色生成
  M5.Display.fillScreen(randomColor);
  
  // 背景色に対してコントラストの良い文字色を設定
  uint16_t textColor = (randomColor < 0x6000) ? WHITE : BLACK;
  M5.Display.setTextColor(textColor);
  
  // テキストを再描画
  M5.Display.setCursor(0, 0);
  M5.Display.println("5秒ごとに\n色が変わります");
}

void setup() {
  auto cfg = M5.config();
  cfg.serial_baudrate = 115200;
  M5.begin(cfg);
  M5.Display.setRotation(3);
  M5.Display.setFont(&fonts::lgfxJapanGothic_16);
  M5.Display.setTextSize(2);
  
  // ランダムシードを初期化
  randomSeed(millis());
  
  // 初期背景色を設定
  changeBackgroundColor();
  
  M5.Display.setTextScroll(true);
  M5.Display.setBrightness(255);
  
}

void loop() {
  M5.update(); // ここではキーを使用しないが、将来的にキー入力を処理する場合はこの関数が必要
  
  changeBackgroundColor();
  
  Serial.println("5秒ごとに色が変わります。");
  M5.delay(5000); 
}
// 書き込み方法: https://scrapbox.io/iot-programming/Build_on_Server を参照してください。