@b707
#include <ESP8266WebServer.h>
#include <DMDESP.h>
#include <DMD.h>
#include <fonts/ElektronMart6x12.h>
#include <fonts/Mono5x7.h>
#include <fonts/EMSans8x16.h>
#include "Arial_black_16.h"
#include <fonts/fixednums15x31.h>
const char* ssid = "NodeMCU_ESP8266";
const char* password = "goodluck";
ESP8266WebServer server(80);
#define DISPLAYS_WIDE 4
#define DISPLAYS_HIGH 2
DMDESP Disp(DISPLAYS_WIDE, DISPLAYS_HIGH);
char *Text[] = {"Hello"};
char *DC = "123456";
char *date = "01-01-24";
char Fuels[4][8] = {"94 .12", "90 .11", "104.21","101.42"};
String FuelsPostfix[4] = {"Petrol", "Diesel", "Speed", "Speed 2"};
String Incoming_Text = "";
bool scrollComplete = false; // Flag to track when scrolling is complete
bool displayDCandDateComplete = false; // Track completion of "DC" and "date" display
int currentFuelIndex = 0; // Track which element of Fuels is currently displayed
bool fuelDisplayComplete = false; // Flag to indicate if we've cycled through all Fuels elements
const char MAIN_page[] PROGMEM = R"=====(
)=====";
void setup(){
Serial.begin(115200);
delay(500);
Disp.start();
Disp.setBrightness(100);
}
bool isScrollingComplete = false;
void drawTextWithReducedSpacing(int x, int y, String text, int letterSpacing, int numberSpacing, int spacingForOne, int spacingBeforeOne) {
int currentX = x;
for (int i = 0; i < text.length(); i++) {
char c = text[i];
if (c == '1' && i > 0 && text[i - 1] != ' ') {
currentX += spacingBeforeOne;
}
Disp.drawChar(currentX, y, c);
if (c == '1') {
currentX += Disp.charWidth(c) + spacingForOne;
} else if (isdigit(c)) {
currentX += Disp.charWidth(c) + numberSpacing;
} else {
currentX += Disp.charWidth(c) + letterSpacing;
}
}
}
void drawTextWithReducedSpacingRow2(int x, int y, String text, int letterSpacing, int numberSpacing, int spacingForOne, int spacingBeforeOne) {
int currentX = x;
for (int i = 0; i < text.length(); i++) {
char c = text[i];
if (c == '1' && i > 0 && text[i - 1] != ' ') {
currentX += spacingBeforeOne;
}
// Draw character flipped vertically for row 2
Disp.drawChar(currentX, 31 - y, c); // Flip y-axis for row 2
if (c == '1') {
currentX += Disp.charWidth(c) + spacingForOne;
} else if (isdigit(c)) {
currentX += Disp.charWidth(c) + numberSpacing;
} else {
currentX += Disp.charWidth(c) + letterSpacing;
}
}
}
void displayScrollingTextRow1() {
static uint32_t prevMillis = 0;
static int xPos = Disp.width(); // Start from the right
int textWidth = Disp.textWidth(Text[0]);
int fullScroll = textWidth + Disp.width();
if (millis() - prevMillis > 50) { // Adjust scrolling speed here
prevMillis = millis();
// Clear display to avoid overlapping text during scrolling
Disp.clear();
Disp.drawText(xPos, 16, Text[0]);
Disp.setFont(EMSans8x16);
xPos--; // Move left
if (xPos < -textWidth) {
xPos = Disp.width(); // Reset position to start from the right again
isScrollingComplete = true; // Mark scrolling as complete
}
}
}
void SlideDownDCandDate(int x, uint8_t sliding_speed) {
static uint32_t pM;
static int y = -17; // Initial position for sliding text
static uint32_t pauseTimer = 0;
static bool isPaused = false;
int dcXPosition = 0;
int dateXPosition = 0;
String dealerCodeText = "DealerNo:" + String(DC);
if ((millis() - pM) > sliding_speed) {
pM = millis();
if (!isPaused) {
if (y < 0) {
++y;
Disp.clear();
// Display 'dc' on row 1 (fixed position on row 1)
Disp.setFont(EMSans8x16);
Disp.drawText(dcXPosition, (y) + 16, dealerCodeText.c_str()); // Fix dc position on row 1
// Display 'date' on row 2 (apply sliding effect for row 2)
Disp.setFont(EMSans8x16);
drawTextWithReducedSpacing(dateXPosition, y, date, 0, 0, 0, 0); // Sliding for row 2
} else {
isPaused = true;
pauseTimer = millis();
}
} else {
if ((millis() - pauseTimer) > 5000) {
y = -23;
isPaused = false;
isScrollingComplete = true; // Reset to allow scrolling again
Disp.clear();
displayDCandDateComplete = true; // Set flag to true when DC and date finish displaying
} else {
// Keep 'dc' in its final position on row 1
Disp.setFont(EMSans8x16);
Disp.drawText(dcXPosition, 16, dealerCodeText.c_str()); // Fixed at y = 16 for row 1
// Keep 'date' in its final position on row 2
drawTextWithReducedSpacing(dateXPosition, 0, date, 0, 0, 0, 0); // Keep final position for row 2
}
}
}
}
void SlideDownFuels(int x, uint8_t sliding_speed) {
if (!displayDCandDateComplete) return; // Only start if DC and date display is complete
static uint32_t pM;
static int y = -17; // Initial vertical position for sliding text
static int currentFuelIndex = 0; // Index of the current fuel being displayed
static uint32_t pauseTimer = 0; // Timer for pausing between elements
static bool isPaused = false; // Pause state
if ((millis() - pM) > sliding_speed) {
pM = millis();
if (!isPaused) {
if (y < 0) {
++y;
Disp.clear();
// Check if the current fuel value contains a dot '.'
String fuelValue = Fuels[currentFuelIndex];
int dotPosition = fuelValue.indexOf('.');
if (dotPosition != -1) {
// Split the fuel value into two parts: before and after the dot
String part1 = fuelValue.substring(0, dotPosition); // Before the dot
String part2 = fuelValue.substring(dotPosition + 1.5); // After the dot
// Display part1 with fixednums15x31 font
Disp.setFont(fixednums15x31);
Disp.drawText(x, y + 16, part1);
// Adjust x position for part2 based on the length of part1
int xPart2 = (part1.length() == 2) ? (x + 48) : (x + (part1.length() * 16));
// Display part2 with EMSans8x16 font (smaller font)
Disp.setFont(EMSans8x16);
Disp.drawText(xPart2, y + 16, part2);
}
// Display the postfix with EMSans8x16 font
Disp.setFont(EMSans8x16);
Disp.drawText(x + 66, y + 16, FuelsPostfix[currentFuelIndex]); // Display postfix below the Fuels value
} else {
isPaused = true;
pauseTimer = millis();
}
} else {
if ((millis() - pauseTimer) > 5000) {
// Move to the next fuel element after 5 seconds
y = -1; // Reset slide position
isPaused = false;
currentFuelIndex = (currentFuelIndex + 1) % 4; // Cycle through 0 to 3
Disp.clear();
// If all Fuels are displayed, mark the cycle as complete
if (currentFuelIndex == 0) {
fuelDisplayComplete = true; // All Fuels have been displayed
}
} else {
// Keep the current fuel element and postfix in their final positions during pause
Disp.setFont(fixednums15x31);
Disp.drawText(x, -17, Fuels[currentFuelIndex]); // Keep Fuels at position 0
Disp.setFont(EMSans8x16);
Disp.drawText(x + 66, -17, FuelsPostfix[currentFuelIndex]); // Keep postfix below the Fuels value
}
}
}
}
void loop() {
server.handleClient();
Disp.loop();
// Display Scrolling Text until complete
if (!isScrollingComplete) {
displayScrollingTextRow1();
delay(1); // Optional delay for scrolling speed control
}
// Display DC and date after scrolling text completes
else if (!displayDCandDateComplete) {
SlideDownDCandDate(0, 50); // Adjust speed for the sliding effect
delay(1);
}
// Display Fuels values after DC and Date are displayed
else if (!fuelDisplayComplete) {
SlideDownFuels(0, 50); // Display Fuels values one at a time
}
// After Fuels have been displayed, restart the sequence
else {
// Reset flags to restart the entire process
isScrollingComplete = false;
displayDCandDateComplete = false;
fuelDisplayComplete = false;
// Optionally clear display to prepare for the next cycle
Disp.clear();
// Add a small delay before restarting
delay(1000);
}
}
Here's the full code for it