Hi All,
I make a sketch that run a long text pixel by pixel using only 2 panel defined in softDMD dmd.
/*
Sketch for displaying running text per column for long text.
however i could only make it run use fixed width font only (ex: SystemFont5x7.h)
*/
#include <SPI.h>
#include <DMD2.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial_Black_16.h>
SoftDMD dmd(2, 1, 9, 8, 7, 4, 5, 3); //2 panels width, 1 panel height, 8,7,4,5,3 are my defined pins
DMD_TextBox box(dmd, 0, 0, 64, 16);
DMD_TextBox box2(dmd, 0, 8, 64, 16);
char teks[] = "Lazy Brown Fox Is Jumping Completely Over A Bunch of Straws Without Getting Down "; // text to display
int colLength;
long currentMillis;
long previousTextMillis;
int textScrollingInterval = 200;
int col = 64;
int charIndex = 0;
boolean charIndexChanged = true;
int sizeOfTeks;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
dmd.setBrightness(100);
dmd.selectFont(SystemFont5x7);
dmd.begin();
Serial.println("begin");
Serial.print("teks = <"); Serial.print(teks); Serial.println(">");
Serial.print("jumlah char = "); Serial.println(sizeof(teks) - 1);
// trimming function
// code below is used to trim excessed space at the end of the text, must find 2 or more space to be identified as excessive space.
// just comment the code to unuse it.
char * p = strstr (teks, " ");
// end of trimming function
sizeOfTeks = (p - teks + 1) - 1;
Serial.print("text = <"); Serial.print(teks); Serial.println(">");
Serial.print("jumlah char = "); Serial.println(sizeof(teks) - 1);
colLength = ((sizeof(teks) - 1) * 5) + (sizeof(teks) - 2);
Serial.print("total kolom = "); Serial.print(colLength);
}
// the loop routine runs over and over again forever:
void loop() {
currentMillis = millis();
if (charIndexChanged) {
charIndexChanged = false;
box2.clear();
box2.print(F("Index = ")); box2.print(charIndex);
}
if (currentMillis - previousTextMillis >= textScrollingInterval) { // using several things at the same time technique
dmd.drawString(col , 0, &teks[charIndex]); // begin draw text from first index running from most right column of the display
if (col == -5) { // -5 used as a buffer when char is hiding after most left column of the display
col = 1; // -5 is used since we use fixed font 5x7
charIndexChanged = true;
charIndex += 1;
}
if (charIndex == sizeOfTeks) { // after all text is hiding to left column of the display
col = 65; // index will reset so text will display again from most right column
charIndex = 0;
box.clear();
box2.clear();
}
col--;
previousTextMillis += textScrollingInterval;
}
}
However it can only run for a font that have a fixed width such as systemfont5x7.
I am unable to retrieve a font data width from font file that have a dynamic width due to my lack of programming skill.
Any ideas will be very appreciated.