fix scrollingtext function for matrix controller

This commit is contained in:
2025-05-27 14:50:37 +02:00
parent 7b81c1dda8
commit 5104f71dc6

View File

@@ -38,7 +38,7 @@
// lines are arranged in columns, progressive order. The shield uses // lines are arranged in columns, progressive order. The shield uses
// 800 KHz (v2) pixels that expect GRB color data. // 800 KHz (v2) pixels that expect GRB color data.
void scrollingText(String text, int speed); void scrollingText(String text, int speed, int color);
void playGif(const uint16_t* gifData[], int frameCount, int frameDelay); void playGif(const uint16_t* gifData[], int frameCount, int frameDelay);
void displayFullScreenBMP(const uint16_t* bitmap); void displayFullScreenBMP(const uint16_t* bitmap);
@@ -53,30 +53,40 @@ const uint16_t colors[] = {
void setup() { void setup() {
matrix.begin(); matrix.begin();
matrix.setTextWrap(false); matrix.setTextWrap(false);
matrix.setBrightness(40); matrix.setBrightness(10);
matrix.setTextColor(colors[0]); matrix.setTextColor(matrix.Color(255, 255, 255));
} }
int x = matrix.width(); int x = matrix.width();
int pass = 0; int pass = 0;
void loop() { void loop() {
displayFullScreenBMP(EEP); scrollingText("Hello World!", 100, 0xFFFFFF);
} }
void scrollingText(String text, int speed) { void scrollingText(String text, int speed, int color) {
matrix.fillScreen(0); // Save original position and color state
matrix.setCursor(x, 0); int textX = matrix.width();
matrix.print(text); int textPass = 0;
matrix.setTextColor(color);
if(--x < -(text.length() * 6)) {
x = matrix.width(); // Calculate the total scroll distance needed for the text to completely scroll through
if(++pass >= 3) pass = 0; // We want to scroll until the text has fully entered from the right AND fully exited to the left
matrix.setTextColor(colors[pass]); int textWidth = text.length() * 6; // Approx 6 pixels per character
int totalScrollDistance = matrix.width() + textWidth;
// Continue scrolling until the text has completely passed through
for (int i = 0; i < totalScrollDistance; i++) {
matrix.fillScreen(0);
matrix.setCursor(textX, 0);
matrix.print(text);
matrix.show();
// Move text position one pixel to the left
textX--;
delay(speed);
} }
matrix.show();
delay(speed);
} }
void playGif(const uint16_t* gifData[], int frameCount, int frameDelay) { void playGif(const uint16_t* gifData[], int frameCount, int frameDelay) {