Add AtomS3R button color demo
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
.pio/
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch/
|
||||||
|
|
||||||
@@ -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.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[env:m5stack-atoms3r]
|
||||||
|
platform = espressif32
|
||||||
|
board = m5stack-atoms3
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
|
lib_deps =
|
||||||
|
m5stack/M5Unified@^0.2.19
|
||||||
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <M5Unified.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user