P10 board DIMMING AND BRIGHTNING issue



#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"

const char* ssid = "NodeMCU_ESP8266";
const char* password = "goodluck";

ESP8266WebServer server(80); 

#define DISPLAYS_WIDE 6 
#define DISPLAYS_HIGH 1 
DMDESP Disp(DISPLAYS_WIDE, DISPLAYS_HIGH);  

char *Text = "Hello";
char *DC   = "123456";
char *date = "01-01-24";
char Fuels[4][8] = {"00.00", "00.00", "000.0","000.0"};

String Incoming_Text = ""; 
bool scrollComplete = false; // Flag to track when scrolling is complete

const char MAIN_page[] PROGMEM = R"=====(
)=====";

void handleRoot() {
  server.send(200, "text/html", MAIN_page); 
}

void handle_Incoming_Text() {
  Incoming_Text = server.arg("TextContents");
  server.send(200, "text/plain", ""); 
  Process_Incoming_Text();
}

void Process_Incoming_Text() {
  delay(500);
  Serial.println("Incoming text : ");
  Serial.println(Incoming_Text);
  Serial.println();
  int str_len = Incoming_Text.length() + 1;
  char char_array[str_len];
  Incoming_Text.toCharArray(char_array, str_len);
  strcpy(Text, char_array);
  Incoming_Text = "";
}

void setup() {
  Serial.begin(115200);
  delay(500);

  Disp.start(); 
  Disp.setBrightness(100); 
  Disp.setFont(Mono5x8); 

  WiFi.softAP(ssid, password);  
  Serial.println("");
  
  IPAddress apip = WiFi.softAPIP(); 
  Serial.print("Connect your wifi laptop/mobile phone to this NodeMCU Access Point : ");
  Serial.println(ssid);
  Serial.print("Visit this IP : ");
  Serial.print(apip); 
  Serial.println(" in your browser.");

  server.on("/", handleRoot); 
  server.on("/setText", handle_Incoming_Text);  
  server.begin(); 
  Serial.println("HTTP server started");
}

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; // Adjust the position before '1' if the previous character is not a space
    }

    Disp.drawChar(currentX, y, c);
    
    if (c == '1') {
      currentX += Disp.charWidth(c) + spacingForOne; // Adjust character position by character width + custom spacing for '1'
    } else if (isdigit(c)) {
      currentX += Disp.charWidth(c) + numberSpacing; // Adjust character position by character width + custom spacing for numbers
    } else {
      currentX += Disp.charWidth(c) + letterSpacing; // Adjust character position by character width + custom spacing for letters
    }
  }
}

void Scrolling_Text(int y, uint8_t scrolling_speed) {
  static uint32_t pM;
  static uint32_t x = 0;
  int displayLimit = 192;  // Limit scrolling area to 192 pixels (first 3 P10 panels)
  Disp.setFont(EMSans8x16);
  int textWidth = Disp.textWidth(Text);
  int fullScroll = textWidth + displayLimit/2;

  if ((millis() - pM) > scrolling_speed) { 
    pM = millis();

    if (x < fullScroll) {
      ++x;
    } else {
      x = 0; // Reset scroll position to start again
      scrollComplete = true; // Signal that scrolling is done
      return; 
    }

    // Clear the entire screen (you may want to adjust this if it causes flickering)
    Disp.clear();

    // Draw text only within the first 192 pixels (the width of 3 P10 panels)
    int textPosition = displayLimit - x;

    if (textPosition + textWidth > 0) {  // Only draw if part of the text is within the visible area
      // Only draw up to the 192 pixels
      if (textPosition < displayLimit) {
        Disp.drawText(textPosition, y, Text);
      }
    }
  }
}


void Sliding_Down(int x, uint8_t sliding_speed) {
  static uint32_t pM;
  static int y = -23; 
  static uint32_t pauseTimer = 0;
  static bool isPaused = false;
  int dcHeight = 8;  
  int dateHeight = 8;  
  
  int dcXPosition = 64;           
  int dateXPosition = 0;       

  // Create the full string for the "Dealer Code"
  String dealerCodeText = "DealerNo:" + String(DC);  // Concatenate "Dealer Code: " with the value of DC

  if ((millis() - pM) > sliding_speed) { 
    pM = millis();
    
    if (!isPaused) {
      if (y < 0) {  
        
        ++y;
        Disp.clear();
        
        Disp.setFont(EMSans8x16);
        // Display the concatenated "Dealer Code: " followed by the value of dc
        Disp.drawText(dcXPosition, y, dealerCodeText.c_str()); 
        
        Disp.setFont(EMSans8x16);
        drawTextWithReducedSpacing(dateXPosition, y, date, 0, 0, 0, 0);
      } else {
        
        isPaused = true;
        pauseTimer = millis();
      }
    } else {
     
      if ((millis() - pauseTimer) > 5000) { 
        y = -23;
        isPaused = false;
        scrollComplete = false;
        Disp.clear(); 
      } else {
        Disp.setFont(EMSans8x16);
        // Redraw the "Dealer Code" with the DC value
        Disp.drawText(dcXPosition, 0, dealerCodeText.c_str());  
        drawTextWithReducedSpacing(dateXPosition, 0, date, 0, 0, 0, 0);  
      }
    }
  }
}


void loop() {
  server.handleClient();
  Disp.loop();
  delay(1);

  if (!scrollComplete) {
    Scrolling_Text(0, 50);
  } else {
    Sliding_Down(0, 60);
  }
}

This is my code to display data on p10 board using esp8266 but the issue i am facing is while displaying the non scrolling values it flickers a lot
can anyone help me to solve this problem?``

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

#include #include #include #include #include #include #include "Arial_black_16.h"

What is this intended to do ?

I've updated it

@UKHeliBob pls helpp!

Sorry, but I am not sure that I can as I am not familiar with the library

Hi, @20kathan
This looks like a display probem, I'll ask a moderator to move the thread to the display part of the forum.

Tom.. :smiley: :+1: :coffee: :australia:

I didn't understand @TomGeorge