Alpha I'm using the code you posted above and I'm trying to take the values that it's printing and put them into another array. I changed your code slightly though so that it goes through all the rows in a column of the letter before moving to the next column. This simplifies things for me when I want to add those numbers to another array. A weird thing is happening though, every other letter is backwards. Actually every letter is backwards, I just couldn't figure it out because A and M are both identical forwards and backwards. I can't figure out why, it was also happening with your original code.
int Tx = 0;
int Ty = 0;
//this is what defines a Letter on the most primitive letter
struct BaseLetter {
virtual char get( byte line, byte bit ) = 0;
virtual byte width( void ) = 0;
static const byte NUMBER_OF_LINES = 5;
};
//Define letters of variable width using this template struct
template<byte size>
struct Letter : public BaseLetter {
Letter( byte l0, byte l1, byte l2, byte l3, byte l4) :
line0(l0),line1(l1),line2(l2),line3(l3),line4(l4) {
}
unsigned line0 : size;
unsigned line1 : size;
unsigned line2 : size;
unsigned line3 : size;
unsigned line4 : size;
unsigned : 0;
virtual char get( byte line, byte bit ) {
switch (line){
case 0: return (line0&(1<<bit%size)?1:0); break;
case 1: return (line1&(1<<bit%size)?1:0); break;
case 2: return (line2&(1<<bit%size)?1:0); break;
case 3: return (line3&(1<<bit%size)?1:0); break;
case 4: return (line4&(1<<bit%size)?1:0); break;
}
return -1;
}
virtual byte width() { return size; }
};
/*
DEFINE THE LETTERS
*/
Letter<3> A = Letter<3>(
B010,
B101,
B111,
B101,
B101
);
Letter<5> M = Letter<5>(
B10001,
B11011,
B10101,
B10001,
B10001
);
Letter<5> N = Letter<5>(
B10001,
B11001,
B10101,
B10011,
B10001
);
Letter<3> Z = Letter<3>(
B111,
B001,
B010,
B100,
B111
);
Letter<1> Ls = Letter<1>(
B0,
B0,
B0,
B0,
B0
);
/*
DEFINE THE WORD
*/
const byte WORD_LENGTH = 7;
BaseLetter* word1[WORD_LENGTH] = { &A, &Ls, &N, &Ls, &M, &Ls, &Z };
char Text[5][5*WORD_LENGTH];
void setup() {
Serial.begin(9600);
//Create Text array of just 0s
for(Ty=0;Ty<(5*WORD_LENGTH);Ty++){
for(Tx=0;Tx<=5;Tx++){
Text[Tx][Ty]=0;
}
}
Tx=0;
Ty=0;
//Take letters and put them into text array
for (int wordIndex=0; wordIndex<WORD_LENGTH; wordIndex++){
//loop through all the columns
for (int bit=0; bit<word1[wordIndex]->width(); bit++){
//loop through all the rows
for (int line=0; line<BaseLetter::NUMBER_OF_LINES; line++){
//print the value at the current letter, at the current line at the current bit
//Serial.print(word1[wordIndex]->get(line,bit),DEC);
Text[Tx][Ty]=int(word1[wordIndex]->get(line,bit));
Tx++;
//Serial.print(Text[Tx][Ty],DEC);
}
//Serial.println();
Tx=0;
Ty++;
}
}
Tx = 0;
Ty = 0;
//Print out text array for analysis
for(Tx=0;Tx<5;Tx++){
for(Ty=0;Ty<(5*WORD_LENGTH);Ty++){
Serial.print(Text[Tx][Ty],DEC);
}
Serial.println();
}
}
void loop() {
}
As a workaround I changed the for loop that looped through the columns from This
for (int bit=0; bit<word1[wordIndex]->width(); bit++)
to This
for (int bit=(word1[wordIndex]->width()-1); bit>=0; bit--)
It just starts at the last column and works toward the first. I'm still curious as to why they were backwards, I believe it has something to do with the get function but I don't know why.