I have been playing around with your code and evererytime my banner gets bigger than 11 characters (including the null) the screen freaks out on me?
#include "MatrixDisplay.h"
#include "DisplayToolbox.h"
#include "font.h"
#define DEMOTIME 30000 // 30 seconds max on each demo is enough.
#define DISPDELAY 100 // Each "display" lasts this long
#define LONGDELAY 1000 // This delay BETWEEN demos
#define SCROLLSPEED 50 /// time in Miliseconds to wait between shifts
#define MAXSTRING 50
// Macro to make it the initDisplay function a little easier to understand
#define setMaster(dispNum, CSPin) initDisplay(dispNum,CSPin,true)
#define setSlave(dispNum, CSPin) initDisplay(dispNum,CSPin,false)
const byte nDisp = 2;// Number of displays
const byte pinData = 10;// Data = 10/
const byte pinWR = 11;// WR == 11
const byte pinCS1 = 9; //
const byte pinCS2 = 8;
// Init Matrix
MatrixDisplay disp(nDisp,pinWR,pinData, true);
// Pass a copy of the display into the toolbox
DisplayToolbox toolbox(&disp);
// Prepare boundaries
uint8_t X_MAX = 0;
uint8_t Y_MAX = 0;
//setup banner
char banner[MAXSTRING];
void setup() {
// Fetch bounds (dynamically work out how large this display is)
X_MAX = disp.getDisplayCount() * (disp.getDisplayWidth()-1)+1;
Y_MAX = disp.getDisplayHeight();
// Prepare displays
disp.setMaster(0,pinCS1);
disp.setSlave(1,pinCS2);
// disp.setSlave(2,6);
// disp.setSlave(3,7);
}
void loop() {
strcpy(banner,"01234567890");
scrollText();
delay(100);
}
/*
* Copy a character glyph from the myfont data structure to
* display memory, with its upper left at the given coordinate
* This is unoptimized and simply uses setPixel() to draw each dot.
*/
void drawChar(uint8_t x, uint8_t y, char c)
{
uint8_t dots;
if (c >= 'A' && c <= 'Z' ||
(c >= 'a' && c <= 'z') ) {
c &= 0x1F; // A-Z maps to 1-26
}
else if (c >= '0' && c <= '9') {
c = (c - '0') + 27;
}
else if (c == ' ') {
c = 0; // space
}
for (char col=0; col< 5; col++) {
dots = pgm_read_byte_near(&myfont[c][col]);
for (char row=0; row < 7; row++) {
if (dots & (64>>row)) // only 7 rows.
toolbox.setPixel(x+col, y+row, 1);
else
toolbox.setPixel(x+col, y+row, 0);
}
}
}
// Write out an entire string (Null terminated)
void drawString(uint8_t x, uint8_t y, char* c)
{
for(char i=0; i< strlen(c); i++)
{
drawChar(x, y, c[i]);
x+=6; // Width of each glyph
}
}
void scrollText(){
int x = X_MAX;
int charsFinished = 0;
char visible[11]; //create visible array to hold string
int i = 0;
unsigned long lastUpdate = 0; //variable used for scrolling function
for (int n = 0; n < 11; n++){ //fill visible array with first char of string
visible[n] = banner[n];
}
while(charsFinished < strlen(banner)){ //while string still has characters
if(millis() - lastUpdate > SCROLLSPEED){
lastUpdate = millis();
drawString(x, 0, visible); //draw visible array
disp.syncDisplays();
x--;
if (x <= -6){ //after each character is finished
charsFinished++; //advance one character
x = 0;
i = 0;
while(i < 11 && banner[i + charsFinished] != '\0'){
visible[i] = banner[i + charsFinished];
i++;
}
visible[i] = banner[i + charsFinished];
}
disp.clear();
}
}
}
any suggestions?