Using fonts and scrolling text for the bicolor 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.

Now we have colors and not like the matrix only 3 colors, black doesn’t count.
We have three colors more
1.) RANDOMCOLOR will change the color for the whole char
2.) MULTICOLOR for all functions, this varies the color for each point
3.) RANDOMCOLUMNCOLOR will draw chars with columns in random colors
Additionally we have two different colors a foreground and a background color.

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_putcharsizecolor(x location, y location , char , size as integer, colorname (RANDOMCOLOR for random color), name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Factory font arrays)
*/
void ht1632_putcharsizecolor(int x, int y,unsigned char c, char size, byte color, byte secondcolor, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven)
{

byte dots, dots2,dots3, cc,cc2, cc3, rr, g, t, t3, divisor;
byte maximumdrawfont, showcolor,showsecondcolor; //128 for the large fonts (=8x8 and 12x8), 64 for all smaller ones
if (rowcountfont<=7)
maximumdrawfont=64;
else
maximumdrawfont=128;
showcolor=color;
showsecondcolor=secondcolor;
if (showcolor==4){
showcolor=random(3)+1;
}
else
{
showcolor=showcolor;}

if (showsecondcolor==4){
showsecondcolor=random(3)+1;
}
else
{
showsecondcolor=showsecondcolor;
}

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]);

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

Call in the loop section:
//Draws a char
// ht1632_putcharsizecolor(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_putcharsizecolor(0,0,'B',2,MULTICOLOR,BLACK,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

/*
* scrolltextsizexcolor()
* Scrolls a text string from left to right
* Original function by Bill Ho
* scrolltextxsizexcolor(y location, string , size as integer, colorname (RANDOMCOLOR for random color), name of the second color (instead of BLACK), 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 scrolltextsizexcolor(int y,char Str1[ ], char size, byte color, byte secondcolor, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven, int delaytime){
int messageLength = strlen(Str1)+ 1;
byte showcolor,showsecondcolor;
int xa = 0;
while (xa (-1 * ( columncountfont*size* messageLength))) {
for (int i = 0; i < messageLength; i++) {
if (color==4){
showcolor=random(3)+1;
}
else
{
showcolor=color;}
if (secondcolor==4){
showsecondcolor=random(3)+1;
}
else
{
showsecondcolor=secondcolor;
}
ht1632_putcharsizecolor(xpos + (columncountfont*size * i), y,Str1[i], size, showcolor, showsecondcolor, 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
// Scrolls the String from left to right
// scrolltextxsize(y location, string , size as integer, colorname (RANDOMCOLOR for random color), name of the second color (instead of BLACK),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
* scrolltextxsizeycolor(y location, string , size as integer, colorname (RANDOMCOLOR for random color), name of the second color (instead of BLACK), name of the font array, number 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, byte color, byte secondcolor, unsigned char fontname[][NCOLUMNS], int columncountfont, char rowcountfont, char oddeven, int delaytime){
int messageLength = strlen(Str1)+ 1;
byte showcolor,showsecondcolor;
int ya = 0;
while (ya (-1 * ( columncountfont*size* messageLength))) {
for (int i = 0; i < messageLength; i++) {
if (color==4){
showcolor=random(3)+1;
}
else
{
showcolor=color;}
if (secondcolor==4){
showsecondcolor=random(3)+1;
}
else
{
showsecondcolor=secondcolor;
}
ht1632_putcharsizecolor(x,ypos + (columncountfont*size * i),Str1[i], size, showcolor, showsecondcolor, fontname, columncountfont, rowcountfont, oddeven);

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

Call in the loop section:
// Scrolls the String from left to right
// scrolltextxsize(x location, string , size as integer, colorname (RANDOMCOLOR for random color), name of the second color (instead of BLACK), name of the font array, umber of columns, number of rows, 'G' for Gimp or 'T' for The Dot Facto

scrolltextsizey(0,"Test ",1,GREEN, 0,my2font,8,8,'G',0); //don't forget the space chars on the end

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