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
|
// 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) {
|
||||||
|
Reference in New Issue
Block a user