diff --git a/54_write_sample.sh b/54_write_sample.sh index 147eaac..ee59885 100755 --- a/54_write_sample.sh +++ b/54_write_sample.sh @@ -53,9 +53,7 @@ $BUILD_TOOL --chip esp32 --port "$PORT" --baud 460800 write-flash -z \ 0x1000 "$BOOTLOADER_PATH" \ 0x8000 "$PARTITIONS_PATH" \ - 0x10000 "$FIRMWARE_PATH" - -echo "Flashing completed." + 0x10000 "$FIRMWARE_PATH" && echo "Flashing completed." # Open serial monitor read -p "シリアルモニタを開きますか?(y/n): " yn diff --git a/Sample/Sample.ino b/Sample/Sample.ino index 28c5f39..d701685 100644 --- a/Sample/Sample.ino +++ b/Sample/Sample.ino @@ -1,20 +1,45 @@ #include +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.println("SampleProject"); + M5.Display.setTextSize(2); + + // ランダムシードを初期化 + randomSeed(millis()); + + // 初期背景色を設定 + changeBackgroundColor(); + M5.Display.setTextScroll(true); M5.Display.setBrightness(255); + } void loop() { - M5.update(); - Serial.println("SampleProjectのプログラムです。"); - M5.delay(2000); + M5.update(); // ここではキーを使用しないが、将来的にキー入力を処理する場合はこの関数が必要 + + changeBackgroundColor(); + + Serial.println("5秒ごとに色が変わります。"); + M5.delay(5000); } // 書き込み方法: https://scrapbox.io/iot-programming/Build_on_Server を参照してください。