|
9 | 9 | const char *ERROR_COLOR = "D70000"; |
10 | 10 | const int HEADSIGN_WIDTH = 6; |
11 | 11 | const char *TRANSIT_COLOR = "3ac364"; |
| 12 | +const char *MESSAGE_COLOR = "FF7B9C"; // Coral pink between peach and hot pink |
12 | 13 | const int DISPLAY_INTERVAL_MS = 10000; // 10 seconds per page |
13 | 14 |
|
14 | 15 | // Global variables for rotation |
15 | 16 | int currentRouteIndex = 0; |
16 | 17 | int totalRoutes = 0; |
| 18 | +bool hasMessage = false; |
| 19 | +bool messageShown = false; |
| 20 | +String currentMessage = ""; |
17 | 21 | JsonDocument globalDoc; // Global to store fetched data |
18 | 22 | MatrixPanel_I2S_DMA *display; // Pointer to display object |
19 | 23 |
|
@@ -133,6 +137,17 @@ void displayDirection(MatrixPanel_I2S_DMA *display, JsonObject direction, |
133 | 137 | display->print("\n"); |
134 | 138 | } |
135 | 139 |
|
| 140 | +/* Function to display a message on the LED matrix */ |
| 141 | +void displayMessage(MatrixPanel_I2S_DMA *display, const char *message) { |
| 142 | + display->fillScreen(0); |
| 143 | + display->setCursor(0, 0); |
| 144 | + display->setTextColor(hexToColor565(MESSAGE_COLOR)); |
| 145 | + display->setTextWrap(true); |
| 146 | + display->println(message); |
| 147 | + display->setTextWrap(false); |
| 148 | + delay(10000); |
| 149 | +} |
| 150 | + |
136 | 151 | /* Function to display a route on the LED matrix */ |
137 | 152 | void displayRoute(MatrixPanel_I2S_DMA *display, JsonObject route) { |
138 | 153 | const char *name = route["name"]; |
@@ -228,29 +243,37 @@ void loop() { |
228 | 243 | totalRoutes = routes.size(); |
229 | 244 | Serial.print("Total routes: "); |
230 | 245 | Serial.println(totalRoutes); |
231 | | - } |
232 | 246 |
|
233 | | - JsonArray routes = globalDoc["routes"]; |
| 247 | + // Check if there's a message to display |
| 248 | + const char *message = globalDoc["message"]; |
| 249 | + if (message != nullptr) { |
| 250 | + currentMessage = String(message); |
| 251 | + Serial.print("Message to display: "); |
| 252 | + Serial.println(currentMessage); |
| 253 | + displayMessage(display, currentMessage.c_str()); |
| 254 | + } |
| 255 | + } |
234 | 256 |
|
235 | 257 | // Clear screen and reset cursor |
236 | 258 | display->fillScreen(0); |
237 | 259 | display->setCursor(0, 0); |
238 | 260 | display->setTextColor(display->color565(255, 255, 255)); |
239 | 261 |
|
240 | 262 | // Display two routes starting from currentRouteIndex |
| 263 | + JsonArray routes = globalDoc["routes"]; |
241 | 264 | for (int i = 0; i < 2 && (currentRouteIndex + i) < totalRoutes; i++) { |
242 | 265 | JsonObject route = routes[currentRouteIndex + i]; |
243 | 266 | displayRoute(display, route); |
244 | 267 | } |
245 | 268 |
|
246 | | - // Wait for display interval |
247 | | - delay(DISPLAY_INTERVAL_MS); |
248 | | - |
249 | 269 | // Move to next pair of routes |
250 | 270 | currentRouteIndex += 2; |
251 | 271 |
|
252 | 272 | // Loop back to start when we reach the end |
253 | 273 | if (currentRouteIndex >= totalRoutes) { |
254 | 274 | currentRouteIndex = 0; |
255 | 275 | } |
| 276 | + |
| 277 | + // Wait for display interval |
| 278 | + delay(DISPLAY_INTERVAL_MS); |
256 | 279 | } |
0 commit comments