Greetings fellow nerds!
I needed to fit a whole alphabet on the Atmega328 but with all the setPixel() for every letter the memory soon got full.
So i came up with this reduction i wanned to share with you. :![]()
This is the function printv(int h, int v,char[] text,byte color)
To write any text to the TV with the setPixel function you can find in Alastair Parkers Arduino Pong(http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187659197)
void printv(int h, int v,char text[],byte col)
{
color=col;
char buffer=-1;
int count=0;
int oldh=0;
int oldv=0;
int letter_width=0;
int sum_width=0;
int line=1;
int i=0;
oldh=h;
oldv=v;
//number of letters
while(buffer != 0){
buffer = text[count];
count++;
}
count=count-1;
while(line<6){
for(i=0;i<count;i++){
if(text[i]=='i'){
letter_width=1;
}
else if(text[i]=='c' ||text[i]=='f' ||text[i]=='j' ||text[i]=='l' ||text[i]=='t'){
letter_width=3;
}
else if(text[i]=='b' || text[i]=='d' || text[i]=='e' || text[i]=='g' || text[i]=='h' || text[i]=='k' || text[i]=='n' || text[i]=='o' || text[i]=='p' || text[i]=='q' || text[i]=='r' || text[i]=='s' || text[i]=='u' || text[i]=='z'){
letter_width=4;
}
else if(text[i]=='a' || text[i]=='m' || text[i]=='v' || text[i]=='w' || text[i]=='x' || text[i]=='y' || text[i]=='z'){
letter_width=5;
}
else{
// letter_width=1;
}
switch(line){
case 1:
if(!(text[i]<97 || text[i]>122)){//not lower case alphabet
if(text[i]!=97 && text[i]!=99 && text[i]!=103 && text[i]!=106 && text[i]!=111 && text[i]!=113 && text[i]!=115){
setPixel(h,v);
}
if(text[i]!=97 && !(text[i]>=104 && text[i]<=110) && !(text[i]>=117 && text[i]<=121)){
setPixel(h+1,v);
}
if(text[i]!=98 && text[i]!=104 && text[i]!=105 && !(text[i]>=107 && text[i]<=110) && !(text[i]>=117 && text[i]<=121)){
setPixel(h+2,v);
}
if(!(text[i]>=97 && text[i]<=100) && text[i]!=102 && text[i]!=105 && text[i]!=106 && text[i]!=108 && text[i]!=109 && !(text[i]>=111 && text[i]<=114) && text[i]!=116 && !(text[i]>=118 && text[i]<=121)){
setPixel(h+3,v);
}
if(!(text[i]>=97 && text[i]<=108) && !(text[i]>=110 && text[i]<=117) && text[i]!=122){
setPixel(h+4,v);
}
}
break;
case 2:
if(!(text[i]<97 || text[i]>122)){
if(text[i]!=97 && text[i]!=106 && text[i]!=116 && !(text[i]>=120 && text[i]<=122)){
setPixel(h,v);
}
if(text[i]!=98 && text[i]!=99 && text[i] != 100 && !(text[i]>=101 && text[i]<=108) && !(text[i]>=111 && text[i]<=115) && !(text[i]>=117 && text[i]<=119) && text[i]!=122){
setPixel(h+1,v);
}
if(text[i]!=97 && text[i]!=99 && text[i] != 100 && !(text[i]>=101 && text[i]<=105) && !(text[i]>=108 && text[i]<=122)){
setPixel(h+2,v);
}
if(text[i] != 98 && text[i] != 99 && !(text[i]>=101 && text[i]<=103) && !(text[i]>=105 && text[i]<=108) && text[i]!=115 && text[i]!=116 && text[i]!=118 && text[i]!=119 ){
setPixel(h+3,v);
}
if(!(text[i]>=97 && text[i]<=108) && !(text[i]>=110 && text[i]<=117) && !(text[i]>=120 && text[i]<=122)){
setPixel(h+4,v);
}
}
break;
case 3:
if(!(text[i]<97 || text[i]>122)){
if(text[i]!=97 && text[i]!=106 && text[i]!=116 && text[i]!=118 && !(text[i]>=120 && text[i]<=122)){
setPixel(h,v);
}
if(text[i]!=99 && text[i]!=100 && text[i]!=103 && text[i]!=105 && text[i]!=106 && !(text[i]>=108 && text[i]<=111) && text[i]!=113 && text[i]!=117 && !(text[i]>=119 && text[i]<=122)){
setPixel(h+1,v);
}
if(text[i]!=97 && text[i]!=99 && text[i]!=100 && text[i]!=102 && text[i]!=105 && text[i]!=107 && text[i]!=108 && text[i]!=111 && text[i]!=113 && !(text[i]>=116 && text[i]<=118)){
setPixel(h+2,v);
}
if(text[i]!=99 && text[i]!=101 && text[i]!=102 && !(text[i]>=105 && text[i]<=109) && text[i]!=116 && !(text[i]>=119 && text[i]<=122)){
setPixel(h+3,v);
}
if(!(text[i]>=97 && text[i]<=108) && !(text[i]>=110 && text[i]<=118) && !(text[i]>=120 && text[i]<=122) ){
setPixel(h+4,v);
}
}
break;
case 4:
if(!(text[i]<97 || text[i]>122)){
if(text[i]!=115 && text[i]!=116 && text[i]!=118 && !(text[i]>=120 && text[i]<=122)){
setPixel(h,v);
}
if(!(text[i]>=98 && text[i]<=115) && text[i]!=117 && text[i]!=119 && text[i]!=121){
setPixel(h+1,v);
}
if(!(text[i]>=98 && text[i]<=105) && !(text[i]>=108 && text[i]<=112) && !(text[i]>=115 && text[i]<=118) && text[i]!=120 && text[i]!=122 ){
setPixel(h+2,v);
}
if(text[i]!=99 && text[i]!=101 && text[i]!=102 && text[i]!=105 && text[i]!=106 && text[i]!=108 && text[i]!=109 && !(text[i]>=112 && text[i]<=114) && text[i]!=116 && text[i]!=119 && text[i]!=121 && text[i]!=122){
setPixel(h+3,v);
}
if(!(text[i]>=98 && text[i]<=108) && !(text[i]>=110 && text[i]<=118) && !(text[i]>=120 && text[i]<=122) ){
setPixel(h+4,v);
}
}
break;
case 5:
if(!(text[i]<97 || text[i]>122)){
if(text[i]!=99 && text[i]!=103 && text[i]!=106 && text[i]!=111 && text[i]!=113 && !(text[i]>=116 && text[i]<=119) && text[i]!=121){
setPixel(h,v);
}
if(text[i]!=97 && text[i]!=102 && text[i]!=104 && text[i]!=105 && text[i]!=107 && text[i]!=109 && text[i]!=110 && text[i]!=112 && text[i]!=114 && text[i]!=118 && text[i]!=120 && text[i]!=121){
setPixel(h+1,v);
}
if(text[i]!=97 && text[i]!=102 && text[i]!=104 && text[i]!=105 && text[i]!=107 && text[i]!=109 && text[i]!=110 && !(text[i]>=112 && text[i]<=114) && text[i]!=116 && text[i]!=119 && text[i]!=120){
setPixel(h+2,v);
}
if(!(text[i]>=97 && text[i]<=100) && text[i]!=102 && text[i]!=105 && text[i]!=106 && text[i]!=108 && text[i]!=109 && text[i]!=111 && text[i]!=112 && text[i]!=115 && text[i]!=116 && text[i]!=118 && text[i]!=120 && text[i]!=121){
setPixel(h+3,v);
}
if(!(text[i]>=98 && text[i]<=108) && !(text[i]>=110 && text[i]<=119) && text[i]!=121 && text[i]!=122){
setPixel(h+4,v);
}
}
break;
}
h=h+letter_width+1;
}
v=v+1;
line++;
h=oldh;
}
}