diff --git a/sketches/doorbell/doorbell.ino b/sketches/doorbell/doorbell.ino index a76cc00..107ae71 100644 --- a/sketches/doorbell/doorbell.ino +++ b/sketches/doorbell/doorbell.ino @@ -18,34 +18,41 @@ const unsigned long BLINK_PERIOD = 1000; #define BACKLIGHT_PIN 22 #define BUTTON_PIN 9 -// Display colors -#define COLOR_BLACK 0x0000 -#define COLOR_RED 0xF800 -#define COLOR_GREEN 0x07E0 -#define COLOR_BLUE 0x001F -#define COLOR_WHITE 0xFFFF -#define COLOR_YELLOW 0xFFE0 +// ============== COCAINE CHIC PALETTE ============== +// Miami Vice meets gallery minimal — neon pastels on stark grounds -// Screen dimensions -#define SCREEN_WIDTH 172 -#define SCREEN_HEIGHT 320 +#define COLOR_BLACK 0x0000 // Midnight void +#define COLOR_COCAINE 0xFFFE // #fff8fa — warm white, almost pink +#define COLOR_TEAL 0x05F5 // #0bd3d3 — electric neon teal +#define COLOR_FUCHSIA 0xFC6E // #f890e7 — hot pink neon +#define COLOR_MINT 0x674D // #64e8ba — mint confirmation + +// Alert alternates between these two states: +#define ALERT_BG_1 COLOR_TEAL // Teal background +#define ALERT_TEXT_1 COLOR_COCAINE // White text +#define ALERT_BG_2 COLOR_FUCHSIA // Fuchsia background +#define ALERT_TEXT_2 COLOR_COCAINE // White text (or try COLOR_BLACK for contrast) + +// Screen dimensions (LANDSCAPE: 320x172) +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 172 // =========================================== -// Arduino_GFX for Waveshare ESP32-C6-LCD-1.47 +// Arduino_GFX for Waveshare ESP32-C6-LCD-1.47 — LANDSCAPE mode Arduino_DataBus *bus = new Arduino_HWSPI( 15 /* DC */, 14 /* CS */, 7 /* SCK */, 6 /* MOSI */, -1 /* MISO */); Arduino_GFX *gfx = new Arduino_ST7789( - bus, 21 /* RST */, 0 /* rotation */, true /* IPS */, - SCREEN_WIDTH, SCREEN_HEIGHT, + bus, 21 /* RST */, 1 /* rotation: LANDSCAPE */, true /* IPS */, + 172 /* native width */, 320 /* native height */, 34 /* col offset 1 */, 0 /* row offset 1 */, 34 /* col offset 2 */, 0 /* row offset 2 */); // =========================================== -enum State { STATE_SILENT, STATE_ALARM }; +enum State { STATE_SILENT, STATE_ALERT }; State currentState = STATE_SILENT; @@ -58,15 +65,15 @@ String lastAlertId = ""; String lastSilenceId = ""; bool lastButtonState = false; -// Store the triggering message for display -String alarmMessage = ""; +String alertMessage = ""; // =========================================== void setup() { Serial.begin(115200); delay(3000); - Serial.println("\n=== MESSAGE DOORBELL ==="); + Serial.println("\n=== COCAINE CHIC DOORBELL ==="); + Serial.println("Aesthetic: Miami Vice minimal, gallery alert"); pinMode(BACKLIGHT_PIN, OUTPUT); digitalWrite(BACKLIGHT_PIN, LOW); @@ -77,7 +84,7 @@ void setup() { Serial.println("Init GFX..."); gfx->begin(); - Serial.println("GFX begin OK"); + Serial.println("GFX begin OK — LANDSCAPE 320x172"); digitalWrite(BACKLIGHT_PIN, HIGH); testDisplay(); @@ -100,18 +107,16 @@ void setup() { Serial.println("\nWiFi FAILED"); digitalWrite(BACKLIGHT_PIN, HIGH); gfx->fillScreen(COLOR_BLACK); - // FIXED: Added yPos parameter (140 = center vertically) - drawCenteredText("NO WIFI", 2, COLOR_RED, COLOR_BLACK, 140); + drawCenteredText("OFFLINE", 3, COLOR_FUCHSIA, COLOR_BLACK, 70); delay(3000); digitalWrite(BACKLIGHT_PIN, LOW); } else { Serial.println("\nWiFi OK: " + WiFi.localIP().toString()); - // Brief status flash digitalWrite(BACKLIGHT_PIN, HIGH); gfx->fillScreen(COLOR_BLACK); - // FIXED: Added yPos parameter (10 = near top) - drawCenteredText("WiFi OK", 2, COLOR_GREEN, COLOR_BLACK, 10); - gfx->setCursor(10, 50); + drawCenteredText("CONNECTED", 2, COLOR_MINT, COLOR_BLACK, 50); + gfx->setTextSize(1); + gfx->setCursor(80, 90); gfx->println(WiFi.localIP().toString()); delay(800); digitalWrite(BACKLIGHT_PIN, LOW); @@ -120,6 +125,7 @@ void setup() { Serial.println("=== SETUP COMPLETE ==="); Serial.println(String("State: ") + getStateName(currentState)); + Serial.println("Silent: screen dark, gallery-ready"); } void loop() { @@ -138,14 +144,14 @@ void loop() { } break; - case STATE_ALARM: + case STATE_ALERT: if (now - lastSilencePoll >= SILENCE_POLL_INTERVAL) { lastSilencePoll = now; checkSilenceTopic(); } updateBlink(now); if (now - blinkStartTime >= BLINK_DURATION) { - Serial.println("ALARM TIMEOUT"); + Serial.println("ALERT TIMEOUT"); transitionTo(STATE_SILENT); } break; @@ -168,55 +174,53 @@ void transitionTo(State newState) { switch (currentState) { case STATE_SILENT: - alarmMessage = ""; + alertMessage = ""; gfx->fillScreen(COLOR_BLACK); digitalWrite(BACKLIGHT_PIN, LOW); - Serial.println("Silent: screen off, message cleared"); + Serial.println("Silent: cocaine white standby, screen dark"); break; - case STATE_ALARM: + case STATE_ALERT: digitalWrite(BACKLIGHT_PIN, HIGH); blinkStartTime = millis(); blinkState = false; - drawAlarmScreen(COLOR_RED, COLOR_WHITE); - Serial.println("ALARM: message displayed"); + drawAlertScreen(ALERT_BG_1, ALERT_TEXT_1); + Serial.println("ALERT: neon pulse activated"); break; } } const char* getStateName(State s) { - return (s == STATE_SILENT) ? "SILENT" : "ALARM"; + return (s == STATE_SILENT) ? "SILENT" : "ALERT"; } -// ============== ALARM SCREEN WITH MESSAGE ============== +// ============== ALERT SCREEN ============== -void drawAlarmScreen(uint16_t bgColor, uint16_t textColor) { +void drawAlertScreen(uint16_t bgColor, uint16_t textColor) { gfx->fillScreen(bgColor); - // Draw "ALARM!" header at top - gfx->setTextSize(2); - gfx->setTextColor(textColor, bgColor); - drawCenteredText("ALARM!", 2, textColor, bgColor, 30); + // "ALERT" header — bold, centered top + drawCenteredText("ALERT", 3, textColor, bgColor, 20); - // Draw the triggering message below, auto-sized - if (alarmMessage.length() > 0) { - drawAutoSizedMessage(alarmMessage, textColor, bgColor, 80); + // The message — auto-sized, centered below + if (alertMessage.length() > 0) { + drawAutoSizedMessage(alertMessage, textColor, bgColor, 70); } } void drawAutoSizedMessage(String message, uint16_t textColor, uint16_t bgColor, int yPos) { - int textSize = calculateOptimalTextSize(message, SCREEN_WIDTH - 20, SCREEN_HEIGHT - yPos - 20); + int textSize = calculateOptimalTextSize(message, SCREEN_WIDTH - 40, SCREEN_HEIGHT - yPos - 20); gfx->setTextSize(textSize); gfx->setTextColor(textColor, bgColor); - gfx->setTextBound(10, yPos, SCREEN_WIDTH - 10, SCREEN_HEIGHT - 10); + gfx->setTextBound(20, yPos, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 10); - gfx->setCursor(10, yPos); + gfx->setCursor(20, yPos); gfx->println(message); } int calculateOptimalTextSize(String message, int maxWidth, int maxHeight) { - for (int size = 4; size >= 1; size--) { + for (int size = 5; size >= 1; size--) { gfx->setTextSize(size); int charWidth = 6 * size; int lineHeight = 8 * size; @@ -224,7 +228,7 @@ int calculateOptimalTextSize(String message, int maxWidth, int maxHeight) { int numLines = (message.length() + charsPerLine - 1) / charsPerLine; int totalHeight = numLines * lineHeight; - if (totalHeight <= maxHeight && charsPerLine >= 5) { + if (totalHeight <= maxHeight && charsPerLine >= 4) { return size; } } @@ -237,7 +241,7 @@ void drawCenteredText(const char* text, int textSize, uint16_t textColor, uint16 int textWidth = strlen(text) * 6 * textSize; int xPos = (SCREEN_WIDTH - textWidth) / 2; - if (xPos < 0) xPos = 0; + if (xPos < 20) xPos = 20; gfx->setCursor(xPos, yPos); gfx->println(text); @@ -251,26 +255,27 @@ void handleButton() { if (pressed && !lastButtonState) { Serial.println("BUTTON PRESSED"); digitalWrite(BACKLIGHT_PIN, HIGH); - gfx->fillScreen(COLOR_WHITE); - drawCenteredText("TEST MODE", 2, COLOR_BLACK, COLOR_WHITE, 140); - Serial.println("Screen WHITE (held)"); + gfx->fillScreen(COLOR_COCAINE); + drawCenteredText("TEST", 3, COLOR_BLACK, COLOR_COCAINE, 70); + Serial.println("Screen COCAINE WHITE (held)"); } else if (!pressed && lastButtonState) { Serial.println("BUTTON RELEASED"); - if (currentState == STATE_ALARM) { - Serial.println("Reset ALARM -> SILENT"); + if (currentState == STATE_ALERT) { + Serial.println("Reset ALERT -> SILENT"); transitionTo(STATE_SILENT); + // Mint confirmation flash digitalWrite(BACKLIGHT_PIN, HIGH); - gfx->fillScreen(COLOR_GREEN); - drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_GREEN, 140); - delay(500); + gfx->fillScreen(COLOR_MINT); + drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_MINT, 70); + delay(400); gfx->fillScreen(COLOR_BLACK); digitalWrite(BACKLIGHT_PIN, LOW); } else { gfx->fillScreen(COLOR_BLACK); digitalWrite(BACKLIGHT_PIN, LOW); - Serial.println("Screen BLACK, backlight OFF"); + Serial.println("Screen BLACK, silent"); } } @@ -311,15 +316,15 @@ void checkAlertTopic() { Serial.println(" -> SILENCE command"); transitionTo(STATE_SILENT); digitalWrite(BACKLIGHT_PIN, HIGH); - gfx->fillScreen(COLOR_GREEN); - drawCenteredText("SILENCE", 3, COLOR_BLACK, COLOR_GREEN, 140); + gfx->fillScreen(COLOR_MINT); + drawCenteredText("SILENCE", 3, COLOR_BLACK, COLOR_MINT, 70); delay(800); gfx->fillScreen(COLOR_BLACK); digitalWrite(BACKLIGHT_PIN, LOW); } else { - Serial.println(" -> TRIGGER ALARM"); - alarmMessage = message; - transitionTo(STATE_ALARM); + Serial.println(" -> TRIGGER ALERT"); + alertMessage = message; + transitionTo(STATE_ALERT); } } @@ -338,12 +343,12 @@ void checkSilenceTopic() { Serial.print("Silence: "); Serial.println((const char*)doc["message"]); - if (currentState == STATE_ALARM) { - Serial.println(" -> Stop alarm via silence topic"); + if (currentState == STATE_ALERT) { + Serial.println(" -> Stop alert via silence topic"); transitionTo(STATE_SILENT); digitalWrite(BACKLIGHT_PIN, HIGH); - gfx->fillScreen(COLOR_GREEN); - drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_GREEN, 140); + gfx->fillScreen(COLOR_MINT); + drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_MINT, 70); delay(800); gfx->fillScreen(COLOR_BLACK); digitalWrite(BACKLIGHT_PIN, LOW); @@ -381,41 +386,44 @@ void updateBlink(unsigned long now) { if (newState != blinkState) { blinkState = newState; - uint16_t bgColor = blinkState ? COLOR_WHITE : COLOR_RED; - uint16_t textColor = blinkState ? COLOR_RED : COLOR_WHITE; - drawAlarmScreen(bgColor, textColor); - Serial.println(blinkState ? "WHITE bg / RED text" : "RED bg / WHITE text"); + + // Cocaine chic alternation: TEAL ↔ FUCHSIA + uint16_t bgColor = blinkState ? ALERT_BG_2 : ALERT_BG_1; + uint16_t textColor = blinkState ? ALERT_TEXT_2 : ALERT_TEXT_1; + + drawAlertScreen(bgColor, textColor); + Serial.println(blinkState ? "FUCHSIA flash" : "TEAL flash"); } } // ============== DISPLAY TEST ============== void testDisplay() { - Serial.println(" RED"); - gfx->fillScreen(COLOR_RED); - delay(100); + Serial.println(" TEAL"); + gfx->fillScreen(COLOR_TEAL); + delay(150); - Serial.println(" GREEN"); - gfx->fillScreen(COLOR_GREEN); - delay(100); + Serial.println(" FUCHSIA"); + gfx->fillScreen(COLOR_FUCHSIA); + delay(150); - Serial.println(" BLUE"); - gfx->fillScreen(COLOR_BLUE); - delay(100); + Serial.println(" COCAINE WHITE"); + gfx->fillScreen(COLOR_COCAINE); + delay(150); - Serial.println(" WHITE"); - gfx->fillScreen(COLOR_WHITE); - delay(100); + Serial.println(" MINT"); + gfx->fillScreen(COLOR_MINT); + delay(150); Serial.println(" BLACK"); gfx->fillScreen(COLOR_BLACK); delay(100); - Serial.println(" TEXT TEST"); + Serial.println(" LANDSCAPE TEXT TEST"); gfx->fillScreen(COLOR_BLACK); - drawCenteredText("GFX OK!", 2, COLOR_WHITE, COLOR_BLACK, 50); - drawCenteredText("Text works!", 2, COLOR_WHITE, COLOR_BLACK, 80); - delay(500); + drawCenteredText("COCAINE", 3, COLOR_COCAINE, COLOR_BLACK, 50); + drawCenteredText("CHIC", 3, COLOR_TEAL, COLOR_BLACK, 90); + delay(400); gfx->fillScreen(COLOR_BLACK); Serial.println("Test complete");