Using fonts and scrolling text for the single color matrix with arduino

This an adaption of the original function by by Bill Westfield (“WestfW”).

Most fonts, also the used in the original function, use 2 dimension arrays, i.e. the font is separated for each char with a brace, that is not bad but you can’t call different fonts with different sizes from one function, at least I’m such an idiot who can’t.
I have also made a ht1632_putcharsize1D function with scrolling function which could call from an array like provided from TheDotFactory but this scrolls right but afterwards it loads endless char from the font. not usefull.

ht1632_putcharsize
An adaption. you can use fonts up to 24 lines, also you can increase the size with integer values. You need to add the number of columns of the font in your header e.g.:
// insert here the number of columns of your font files
// the compiler will comment how large the number of columns
// should be
#define NCOLUMNS 8

/*
* 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 plot() to draw each dot.
* Slightly adopted for using fonts with more rows then 8
* ht1632_putcharsize(x location, y location , char , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays)
*/
void ht1632_putcharsize(int x, int y,unsigned char c, char size, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven)
{

byte dots, dots2,dots3, cc,cc2, cc3, rr, g, t, t3, divisor;
byte maximumdrawfont; //128 for the large fonts (=8x8 and 12x8), 64 for all smaller ones
if (rowcountfont<=7)
maximumdrawfont=64;
else
maximumdrawfont=128;
for (byte col=0; col<columncountfont*size ; col++) {
// Addressing the right 8 lines because 'The Dot Factory' starts from the bottom, all others from top
if (rowcountfont 8 && rowcountfont 16 && rowcountfont <=24){
if (oddeven=='T'){
g=0;
t=1;
t3=2;
}
else {
g=2;
t=1;
t3=0;
}
divisor=3;
cc=col/size*divisor+g;
cc2=col/size*divisor+t;
cc3=col/size*divisor+t3;
dots = pgm_read_byte_near(&fontname[c][cc]);
dots2 = pgm_read_byte_near(&fontname[c][cc2]);
dots3 = pgm_read_byte_near(&fontname[c][cc3]);

}
for (byte row=0; row >rr))
plot(x+col, y+row, 1);
else
plot(x+col, y+row, 0);
if (divisor>=2){
if (dots2 & (maximumdrawfont>>rr))
plot(x+col, y+rowcountfont/divisor+row, 1);
else
plot(x+col, y+rowcountfont/divisor+row, 0);
}
if (divisor>=3){
if (dots3& (maximumdrawfont>>rr))
plot(x+col, y+2*rowcountfont/divisor+row, 1);
else
plot(x+col, y+2*rowcountfont/divisor+row, 0);
}
}
}
}

Call in the loop section:
//Draws a char
// ht1632_putcharsize(x location, y location , char , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays)
ht1632_putcharsize(0,0,'B',2,my2font,8,8,'G');

Scrolling text
The original Scrolling fumction is by Bill Ho, adapted by roomtek http://code.google.com/p/sure-green-matrix/

Scroll a text from left to right

/*
* scrolltextxsize()
* Scrolls a text string from left to right
* Original function by Bill Ho
* scrolltextxsize(y location, string , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays, delaytime in milliseconds)
*/
void scrolltextsizex(int y,char Str1[ ], char size, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven, int delaytime){
int messageLength = strlen(Str1)+ 1;
int xa = 0;
while (xa (-1 * ( columncountfont*size* messageLength))) {
for (int i = 0; i < messageLength; i++) {
ht1632_putcharsize(xpos + (columncountfont*size * i), y,Str1[i], size, fontname, columncountfont, rowcountfont, oddeven);

}
delay(delaytime);// reduce speed of scroll
xpos--;
}
xa =1;
}
}

Call in the loop section:
// Scrolls the String from left to right
// scrolltextxsize(y location, string , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays, delaytime in milliseconds)
scrolltextsizex(1,"Donaudampfschifffahrtskapitaenskajuete ",1,my2font,8,8,'G',30); //longest German word, don't forget the space chars on the end

Scroll from bottom to up

/*
* scrolltextysize()
* Scrolls a text string from bottom to up
* Original function by Bill Ho
* scrolltextxsize(y location, string , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays, delaytime in milliseconds)
*/
void scrolltextsizey(int x,char Str1[ ], char size, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven, int delaytime){
int messageLength = strlen(Str1)+ 1;
int ya = 0;
while (ya (-1 * ( columncountfont*size* messageLength))) {
for (int i = 0; i < messageLength; i++) {
ht1632_putcharsize(x,ypos + (columncountfont*size * i),Str1[i], size, fontname, columncountfont, rowcountfont, oddeven);

}
delay(delaytime);// reduce speed of scroll
ypos--;
}
ya =1;
}
}

Call in the loop section:
// scrolltextsizey(x location, string , size as integer, name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays, delaytime in milliseconds)
scrolltextsizey(0,"Test ",1,my2font,8,8,'G',0); //don't forget the space chars on the end
delay(LONGDELAY);

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s