Skip to content

Scrolling Text and Fixed Text using double buffer #791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ARPROJECT26 opened this issue May 7, 2025 · 2 comments
Open

Scrolling Text and Fixed Text using double buffer #791

ARPROJECT26 opened this issue May 7, 2025 · 2 comments

Comments

@ARPROJECT26
Copy link

Hi @mrcodetastic ,

I have the problem for Scrolling and Fixed Text using double buffer.
I don't want scroll text to overwrite fixed text when scroll text overlap with fixedtext.

any suggestion?

Thanks

`
#include <Arduino.h>
#include <ESP32-HUB75-VirtualMatrixPanel_T.hpp>
#include <Fonts/FreeSerifBold9pt7b.h>

/**

  • Configuration of the LED matrix panels number and individual pixel resolution.
    **/
    #define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
    #define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.

#define VDISP_NUM_ROWS 2 // Number of rows of individual LED panels
#define VDISP_NUM_COLS 2 // Number of individual LED panels per row

#define PANEL_CHAIN_LEN (VDISP_NUM_ROWS * VDISP_NUM_COLS) // Don't change

/**

  • Configuration of the approach used to chain all the individual panels together.
  • Refer to the documentation or check the enum 'PANEL_CHAIN_TYPE' in VirtualMatrixPanel_T.hpp for options.
    **/
    #define PANEL_CHAIN_TYPE CHAIN_TOP_RIGHT_DOWN

/**

  • Optional config for the per-panel pixel mapping, for non-standard panels.
  • i.e. 1/4 scan panels, or outdoor panels. They're a pain in the a-- and all
  •  have their own weird pixel mapping that is not linear.
    
  • This is used for Examples 2 and 3.

**/
#define PANEL_SCAN_TYPE FOUR_SCAN_32PX_HIGH

/**

  • Mandatory declaration of the dma_display. DO NOT CHANGE
    */
    MatrixPanel_I2S_DMA
    dma_display = nullptr;

// ------------------------------------------------------------------------------------------------------------

// --- Example 1: STANDARD 1/2 Scan ---

// Declare a pointer to the specific instantiation:
VirtualMatrixPanel_T<PANEL_CHAIN_TYPE>* virtualDisp = nullptr;

int16_t xOne, yOne;
uint16_t w, h;

int16_t fxOne, fyOne;
uint16_t fw, fh;

unsigned long isAnimationDue;
int delayBetweeenAnimations = 25; // Smaller == faster

// int textXPosition = PANEL_RES_X * PANEL_CHAIN_LEN; // Will start off screen
int textXPosition = 64 * 2; // Will start off screen

// int textYPosition = PANEL_RES_Y / 2 - 8; // center of screen - 8 (half of the text height)
int textYPosition = 8;

uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myRED = dma_display->color565(255, 0, 0);
uint16_t myGREEN = dma_display->color565(0, 255, 0);
uint16_t myBLUE = dma_display->color565(0, 0, 255);

String scrollText = "Scroll Text";
String fixedText = "Fix";

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

HUB75_I2S_CFG mxconfig(
PANEL_RES_X,
PANEL_RES_Y,
PANEL_CHAIN_LEN
//, _pins
);

mxconfig.double_buff = true;
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
mxconfig.clkphase = false;
//mxconfig.driver = HUB75_I2S_CFG::FM6126A;

dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
dma_display->setBrightness8(128); //0-255
dma_display->clearScreen();

virtualDisp = new VirtualMatrixPanel_T<PANEL_CHAIN_TYPE>(VDISP_NUM_ROWS, VDISP_NUM_COLS, PANEL_RES_X, PANEL_RES_Y);

virtualDisp->setDisplay(*dma_display);
virtualDisp->clearScreen();

virtualDisp->fillScreen(myBLACK);

virtualDisp->setTextSize(1); // size 2 == 16 pixels high
virtualDisp->setTextWrap(false); // N.B!! Don't wrap at end of line
virtualDisp->setTextColor(myRED);

String scrollText1 = "ABC";
Serial.println(scrollText1);
// virtualDisp->setFont(&FreeSerifBold9pt7b);

// scrollText1 = scrollText1.substring(0, scrollText1.length() - 1);
// Serial.println(scrollText1);
// scrollText1 = scrollText1.substring(0, scrollText1.length() - 1);
// Serial.println(scrollText1);
}

void loop() {

dma_display->flipDMABuffer();
delay(1000 / dma_display->calculated_refresh_rate);
dma_display->clearScreen();
delay(25);
virtualDisp->setCursor(0, textYPosition);
virtualDisp->print(fixedText);

unsigned long now = millis();
if (now > isAnimationDue) {
isAnimationDue = now + delayBetweeenAnimations;
textXPosition -= 1;

// Checking is the very right of the text off screen to the left
virtualDisp->getTextBounds(scrollText, textXPosition, textYPosition, &xOne, &yOne, &w, &h);
if (textXPosition + w <= 0) {
  textXPosition = 64 * 2;
}
virtualDisp->setCursor(textXPosition, textYPosition);
virtualDisp->print(scrollText);

}

// Serial.println("textXPosition + w");
// Serial.println(textXPosition + w);

// Serial.println("textXPosition");
// Serial.println(textXPosition);
// Serial.println("textYPosition");
// Serial.println(textYPosition);
}`

WhatsApp.Video.2025-05-07.at.14.27.07.mp4
@board707
Copy link
Contributor

board707 commented May 7, 2025

I don't want scroll text to overwrite fixed text when scroll text overlap with fixedtext.

You could first scroll moving text, and then renew a fixed text.

@ARPROJECT26
Copy link
Author

ARPROJECT26 commented May 7, 2025

Hi @board707 ,

Thanks for the response.
I try to move fixedtext after scroll text still issue.

`
#include <Arduino.h>
#include <ESP32-HUB75-VirtualMatrixPanel_T.hpp>
#include <Fonts/FreeSerifBold9pt7b.h>

/**

  • Configuration of the LED matrix panels number and individual pixel resolution.
    **/
    #define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
    #define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.

#define VDISP_NUM_ROWS 2 // Number of rows of individual LED panels
#define VDISP_NUM_COLS 2 // Number of individual LED panels per row

#define PANEL_CHAIN_LEN (VDISP_NUM_ROWS * VDISP_NUM_COLS) // Don't change

/**

  • Configuration of the approach used to chain all the individual panels together.
  • Refer to the documentation or check the enum 'PANEL_CHAIN_TYPE' in VirtualMatrixPanel_T.hpp for options.
    **/
    #define PANEL_CHAIN_TYPE CHAIN_TOP_RIGHT_DOWN

/**

  • Optional config for the per-panel pixel mapping, for non-standard panels.
  • i.e. 1/4 scan panels, or outdoor panels. They're a pain in the a-- and all
  •  have their own weird pixel mapping that is not linear.
    
  • This is used for Examples 2 and 3.

**/
#define PANEL_SCAN_TYPE FOUR_SCAN_32PX_HIGH

/**

  • Mandatory declaration of the dma_display. DO NOT CHANGE
    */
    MatrixPanel_I2S_DMA
    dma_display = nullptr;

// ------------------------------------------------------------------------------------------------------------

// --- Example 1: STANDARD 1/2 Scan ---

// Declare a pointer to the specific instantiation:
VirtualMatrixPanel_T<PANEL_CHAIN_TYPE>* virtualDisp = nullptr;

int16_t xOne, yOne;
uint16_t w, h;

int16_t fxOne, fyOne;
uint16_t fw, fh;

unsigned long isAnimationDue;
int delayBetweeenAnimations = 25; // Smaller == faster

// int textXPosition = PANEL_RES_X * PANEL_CHAIN_LEN; // Will start off screen
int textXPosition = 64 * 2; // Will start off screen

// int textYPosition = PANEL_RES_Y / 2 - 8; // center of screen - 8 (half of the text height)
int textYPosition = 8;

uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myRED = dma_display->color565(255, 0, 0);
uint16_t myGREEN = dma_display->color565(0, 255, 0);
uint16_t myBLUE = dma_display->color565(0, 0, 255);

String scrollText = "Scroll Text";
String fixedText = "Fix";

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

HUB75_I2S_CFG mxconfig(
PANEL_RES_X,
PANEL_RES_Y,
PANEL_CHAIN_LEN
//, _pins
);

mxconfig.double_buff = true;
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
mxconfig.clkphase = false;
//mxconfig.driver = HUB75_I2S_CFG::FM6126A;

dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
dma_display->setBrightness8(128); //0-255
dma_display->clearScreen();

virtualDisp = new VirtualMatrixPanel_T<PANEL_CHAIN_TYPE>(VDISP_NUM_ROWS, VDISP_NUM_COLS, PANEL_RES_X, PANEL_RES_Y);

virtualDisp->setDisplay(*dma_display);
virtualDisp->clearScreen();

virtualDisp->fillScreen(myBLACK);

virtualDisp->setTextSize(1); // size 2 == 16 pixels high
virtualDisp->setTextWrap(false); // N.B!! Don't wrap at end of line
virtualDisp->setTextColor(myRED);

String scrollText1 = "ABC";
Serial.println(scrollText1);
// virtualDisp->setFont(&FreeSerifBold9pt7b);

// scrollText1 = scrollText1.substring(0, scrollText1.length() - 1);
// Serial.println(scrollText1);
// scrollText1 = scrollText1.substring(0, scrollText1.length() - 1);
// Serial.println(scrollText1);
}

void loop() {

dma_display->flipDMABuffer();
delay(1000 / dma_display->calculated_refresh_rate);
dma_display->clearScreen();
delay(25);

unsigned long now = millis();
if (now > isAnimationDue) {
isAnimationDue = now + delayBetweeenAnimations;
textXPosition -= 1;

// Checking is the very right of the text off screen to the left
virtualDisp->getTextBounds(scrollText, textXPosition, textYPosition, &xOne, &yOne, &w, &h);
if (textXPosition + w <= 0) {
  textXPosition = 64 * 2;
}
virtualDisp->setCursor(textXPosition, textYPosition);
virtualDisp->print(scrollText);

}

virtualDisp->setCursor(0, textYPosition);
virtualDisp->print(fixedText);

// Serial.println("textXPosition + w");
// Serial.println(textXPosition + w);

// Serial.println("textXPosition");
// Serial.println(textXPosition);
// Serial.println("textYPosition");
// Serial.println(textYPosition);
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants