toughc5-touch-ui-dashboard.ino
Touch graphical interface with visual and audio feedback via the passive buzzer.
Uses the M5GFX library for optimized rendering on the ILI9342C screen. The capacitive touch detects X/Y coordinates. The buzzer provides audio haptic feedback. Suitable for industrial dashboards.
toughc5-touch-ui-dashboard.ino
#include <M5ToughC5.h>
#include <M5GFX.h>
M5Canvas canvas(&M5.Display);
void drawButton(int x, int y, int w, int h, uint16_t color, const char* text, bool pressed) {
canvas.fillRect(x, y, w, h, pressed ? DARKGREY : color);
canvas.drawRect(x, y, w, h, WHITE);
canvas.setTextColor(WHITE);
canvas.setTextDatum(TL_DATUM);
canvas.drawString(text, x + 5, y + 5);
}
void setup() {
M5.begin();
canvas.setColorDepth(16);
canvas.createSprite(M5.Display.width(), M5.Display.height());
canvas.fillScreen(BLACK);
}
void loop() {
canvas.fillScreen(BLACK);
// Header
canvas.setTextColor(WHITE);
canvas.drawString("System Status", 10, 10);
// Simulated Data
canvas.drawString("Temp: 24.5 C", 10, 40);
canvas.drawString("Hum: 45 %", 10, 60);
// Touchable Area
bool isPressed = M5.Touch.isPressed();
drawButton(10, 100, 100, 40, BLUE, "BTN 1", isPressed);
if (isPressed) {
auto touch = M5.Touch.getDetail();
if (touch.x > 10 && touch.x < 110 && touch.y > 100 && touch.y < 140) {
M5.Speaker.tone(1000, 50); // Feedback sonore via buzzer
canvas.drawString("Pressed!", 120, 115);
}
}
canvas.pushSprite(0, 0);
delay(50);
}