commit 1b335b332bd6e4d9e16127cc62087395d51a1464 Author: Zandozan Date: Sun Aug 2 19:11:49 2026 +0200 Add AtomS3R button color demo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e4cf89e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.pio/ +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch/ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d12b89c --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# M5Stack AtomS3R Color Button + +A simple PlatformIO program for the M5Stack AtomS3R. + +Each press of the screen/button cycles through red, green, blue, yellow, +magenta, cyan, white, and black. The selected color name is drawn in the +center and also printed to the serial monitor at 115200 baud. + +## Build + +```powershell +pio run +``` + +## Upload + +Connect the AtomS3R over USB, then run: + +```powershell +pio run --target upload +``` + +If normal upload mode is not detected, hold the reset button for about two +seconds until the internal green LED lights, release it, and retry the upload. diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..63d0a4e --- /dev/null +++ b/platformio.ini @@ -0,0 +1,8 @@ +[env:m5stack-atoms3r] +platform = espressif32 +board = m5stack-atoms3 +framework = arduino +monitor_speed = 115200 +lib_deps = + m5stack/M5Unified@^0.2.19 + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b02364f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,64 @@ +#include +#include + +namespace { + +struct ScreenColor { + uint32_t value; + const char* name; +}; + +constexpr ScreenColor COLORS[] = { + {TFT_RED, "RED"}, + {TFT_GREEN, "GREEN"}, + {TFT_BLUE, "BLUE"}, + {TFT_YELLOW, "YELLOW"}, + {TFT_MAGENTA, "MAGENTA"}, + {TFT_CYAN, "CYAN"}, + {TFT_WHITE, "WHITE"}, + {TFT_BLACK, "BLACK"}, +}; + +constexpr size_t COLOR_COUNT = sizeof(COLORS) / sizeof(COLORS[0]); +size_t colorIndex = 0; + +void showColor() { + const ScreenColor& color = COLORS[colorIndex]; + M5.Display.fillScreen(color.value); + + // Choose contrasting text so the color name remains readable. + M5.Display.setTextColor(color.value == TFT_WHITE || color.value == TFT_YELLOW + ? TFT_BLACK + : TFT_WHITE); + M5.Display.setTextDatum(middle_center); + M5.Display.setTextSize(2); + M5.Display.drawString(color.name, + M5.Display.width() / 2, + M5.Display.height() / 2); + + Serial.printf("Color: %s\n", color.name); +} + +} // namespace + +void setup() { + auto config = M5.config(); + M5.begin(config); + + Serial.begin(115200); + M5.Display.setRotation(0); + showColor(); +} + +void loop() { + M5.update(); + + // The AtomS3R's screen is also its physical button. + if (M5.BtnA.wasPressed()) { + colorIndex = (colorIndex + 1) % COLOR_COUNT; + showColor(); + } + + delay(10); +} +