Add a power button

This commit is contained in:
Correl Roush 2023-01-20 16:28:31 -05:00
parent bb2b31c042
commit 6a42762e2a

View file

@ -8,10 +8,12 @@ const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; const char* password = "REPLACE_WITH_YOUR_PASSWORD";
AsyncWebServer server(80); AsyncWebServer server(80);
LGFX_Button button_power;
void setup(void) { void setup(void) {
auto cfg = M5.config(); auto cfg = M5.config();
M5.begin(cfg); M5.begin(cfg);
M5.Display.init();
M5.Display.setTextSize(3); M5.Display.setTextSize(3);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
@ -37,6 +39,7 @@ void setup(void) {
server.begin(); server.begin();
Serial.println("HTTP server started"); Serial.println("HTTP server started");
M5.Display.startWrite();
M5.Display.printf("SSID: %s\n", ssid); M5.Display.printf("SSID: %s\n", ssid);
M5.Display.printf("IP Address: %s\n", WiFi.localIP().toString()); M5.Display.printf("IP Address: %s\n", WiFi.localIP().toString());
M5.Display.printf("\n\n"); M5.Display.printf("\n\n");
@ -44,9 +47,28 @@ void setup(void) {
M5.Display.printf("ElegantOTA available at\n" M5.Display.printf("ElegantOTA available at\n"
"http://%s/update\n", "http://%s/update\n",
WiFi.localIP().toString()); WiFi.localIP().toString());
button_power.initButton(&M5.Display, M5.Display.width() / 2, M5.Display.height() / 2, 200, 100, TFT_BLACK, TFT_LIGHTGRAY, TFT_BLACK, "Power", 3, 3);
button_power.drawButton();
M5.Display.endWrite();
} }
void loop() void loop()
{ {
M5.update();
auto t = M5.Touch.getDetail();
if (t.wasPressed()) {
if (button_power.contains(t.x, t.y)) {
button_power.press(true);
} else {
button_power.press(false);
}
} else {
button_power.press(false);
}
if (button_power.justReleased()) {
M5.Display.clearDisplay(TFT_WHITE);
M5.Power.powerOff();
}
yield(); yield();
} }