mirror of
https://gitlab.waag.org/make/fablab/interns/2025/sam.git
synced 2025-08-03 11:54:58 +00:00
fix scrollingtext function for matrix controller
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
// lines are arranged in columns, progressive order. The shield uses
|
||||
// 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 displayFullScreenBMP(const uint16_t* bitmap);
|
||||
|
||||
@@ -53,30 +53,40 @@ const uint16_t colors[] = {
|
||||
void setup() {
|
||||
matrix.begin();
|
||||
matrix.setTextWrap(false);
|
||||
matrix.setBrightness(40);
|
||||
matrix.setTextColor(colors[0]);
|
||||
matrix.setBrightness(10);
|
||||
matrix.setTextColor(matrix.Color(255, 255, 255));
|
||||
}
|
||||
|
||||
int x = matrix.width();
|
||||
int pass = 0;
|
||||
|
||||
void loop() {
|
||||
displayFullScreenBMP(EEP);
|
||||
scrollingText("Hello World!", 100, 0xFFFFFF);
|
||||
}
|
||||
|
||||
void scrollingText(String text, int speed) {
|
||||
matrix.fillScreen(0);
|
||||
matrix.setCursor(x, 0);
|
||||
matrix.print(text);
|
||||
void scrollingText(String text, int speed, int color) {
|
||||
// Save original position and color state
|
||||
int textX = matrix.width();
|
||||
int textPass = 0;
|
||||
matrix.setTextColor(color);
|
||||
|
||||
if(--x < -(text.length() * 6)) {
|
||||
x = matrix.width();
|
||||
if(++pass >= 3) pass = 0;
|
||||
matrix.setTextColor(colors[pass]);
|
||||
// Calculate the total scroll distance needed for the text to completely scroll through
|
||||
// We want to scroll until the text has fully entered from the right AND fully exited to the left
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user