IAN LANG ELECTRONICS

So, now we know how to define bitmaps, we know how to change them and we know how to make text scroll across the matrix. Let's have a sketch that handily celebrates my vanity and brings the modes of animation together.

char requestString[] = " Ian Lang Electronics ";  //The string to display    

int pauseDelay = 300;  //microseconds to leave each row  on before moving to the next                                  

//Variables used for scrolling (both start at 0

int index = 0;  //this is the current character in the string being displayed

int offset = 0; //this is how many columns it is offset by

int rowA[] = {9,8,7,6,5,4,3,2};          //An Array defining which pin each row is attached to                                    

int colA[] = {17,16,15,14,13,12,11,10};  //An Array defining which pin each column is attached to                          

byte data[] = {0,0,0,0,0,0,0,0};     //The array used to hold a bitmap of the display

boolean texton=false;

//The alphabet

//Each Character is an 8 x 7 bitmap where 1 is on and 0 if off. This defines the character bitmaps.

const int _A[] = {B0001000,B0010100,B0100010,B0100010,B0111110,B0100010,B0100010,B0000000};

const int _B[] = {B0111110,B0100001,B0100001,B0111110,B0100001,B0100001,B0111110,B0000000};

const int _C[] = {B0011110,B0100000,B0100000,B0100000,B0100000,B0100000,B0011110,B0000000};

const int _D[] = {B0111100,B0100010,B0100010,B0100010,B0100010,B0100010,B0111100,B0000000};

const int _E[] = {B1111100,B1000000,B1000000,B1111100,B1000000,B1000000,B1111100,B0000000};

const int _F[] = {B0111110,B0100000,B0100000,B0111100,B0100000,B0100000,B0100000,B0000000};

const int _G[] = {B0011111,B0100000,B0100000,B0101111,B0100001,B0100001,B0011111,B0000000};

const int _H[] = {B0100010,B0100010,B0100010,B0111110,B0100010,B0100010,B0100010,B0000000};

const int _I[] = {B0111110,B0001000,B0001000,B0001000,B0001000,B0001000,B0111110,B0000000};

const int _J[] = {B0001111,B0000001,B0000001,B0000001,B0000001,B0100001,B0011110,B0000000};

const int _K[] = {B0100010,B0100100,B0101000,B0110000,B0101000,B0100100,B0100010,B0000000};

const int _L[] = {B1000000,B1000000,B1000000,B1000000,B1000000,B1000000,B1111100,B0000000};

const int _M[] = {B1110110,B1001001,B1001001,B1001001,B1001001,B1001001,B1001001,B0000000};

const int _N[] = {B0100010,B0100010,B0110010,B0101010,B0100110,B0100010,B0100010,B0000000};

const int _O[] = {B0011100,B0100010,B1000001,B1000001,B1000001,B0100010,B0011100,B0000000};

const int _P[] = {B0111110,B0100010,B0100010,B0111110,B0100000,B0100000,B0100000,B0000000};

const int _Q[] = {B0011100,B0100010,B1000001,B1000001,B1000101,B0100010,B0011101,B0000000};

const int _R[] = {B0111110,B0100010,B0100010,B0101110,B0100100,B0100010,B0100001,B0000000};

const int _S[] = {B0111110,B0100000,B0100000,B0111110,B0000010,B0000010,B0111110,B0000000};

const int _T[] = {B1111111,B0001000,B0001000,B0001000,B0001000,B0001000,B0001000,B0000000};

const int _U[] = {B0100010,B0100010,B0100010,B0100010,B0100010,B0100010,B0111110,B0000000};

const int _V[] = {B1000001,B1000001,B1000001,B1000001,B0100010,B0010100,B0001000,B0000000};              

const int _W[] = {B1000001,B1001001,B1001001,B1001001,B1001001,B1001001,B0110110,B0000000};

const int _X[] = {B1000001,B0100010,B0010100,B0001000,B0010100,B0100010,B1000001,B0000000};

const int _Y[] = {B1000001,B0100010,B0010100,B0001000,B0001000,B0001000,B0001000,B0000000};

const int _Z[] = {B1111111,B0000010,B0000100,B0001000,B0010000,B0100000,B1111111,B0000000};        

const int __[] = {B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0000000};

const int __qe[] = {B0011100,B0100010,B0000100,B001000,B0001000,B0000000,B0001000,B0000000};

const int bang[] = {B0001000,B0001000,B0001000,B001000,B0001000,B0000000,B0001000,B0000000};                

const int pound[] = {B0011110,B0010001,B0100000,B1111110,B0100000,B0100000,B1111110,B0000000};

const int plus[] = {B0000000,B0001000,B0001000,B1111111,B0001000,B0001000,B0000000,B0000000};

const int dot[] = {B0000000,B0000000,B0000000,B0000000,B0000000,B0000000,B0001000,B0000000};

const int one[] = {B0001000,B0011000,B0001000,B0001000,B0001000,B0001000,B0111110,B0000000};

const int two[] = {B011100,B0100100,B0001000,B0010000,B0010000,B0100000,B0111100,B0000000};

const int three[] = {B0111100,B0000100,B0000100,B0111100,B0000100,B0000100,B0111100,B0000000};

const int four[] = {B0100000,B0100000,B0100100,B0100100,B0111100,B0000100,B0000100,B0000000};

const int five[] = {B0111100,B0100000,B0100000,B0111100,B0000100,B0000100,B0111100,B0000000};

const int six[] = {B0111100,B0100000,B0100000,B0111100,B0100100,B0100100,B0111100,B0000000};

const int seven[] = {B0111100,B0000100,B0000100,B0000100,B0000100,B0000100,B0000100,B0000000};

const int eight[] = {B0111100,B0100100,B0100100,B0111100,B0100100,B0100100,B0111100,B0000000};

const int nine[] = {B0111100,B0100100,B0100100,B0111100,B0000100,B0000100,B0111100,B0000000};

const int zero[] = {B0111100,B0100100,B0100100,B0100100,B0100100,B0100100,B0111100,B0000000};

const int colon[] = {B00000000,B010100,B00000000,B00000000,B010100,B00000000,B0000000,B0000000};

const int apo[] = {B00001110,B00001110,B00000010,B00000100,B001000,B00000000,B0000000,B0000000};

//Load the bitmap characters into an array

const int* letters[] = {_A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_P,_Q,_R,_S,_T,_U,_V,_W,_X,_Y,_Z,__,__qe,bang,pound,plus,dot,one,two,three,four,five,six,seven,eight,nine,zero,colon,apo};

int getChar(char character){//extraneous function

 int getChar = 26;

 switch(character){

case 65: getChar = 0; break;

case 'a': getChar = 0; break;

case 'B': getChar = 1; break;

case 'b': getChar = 1; break;

case 'C': getChar = 2; break;

case 'c': getChar = 2; break;

case 'D': getChar = 3; break;

case 'd': getChar = 3; break;

case 'E': getChar = 4; break;

case 'e': getChar = 4; break;

case 'F': getChar = 5; break;

case 'f': getChar = 5; break;

case 'G': getChar = 6; break;

case 'g': getChar = 6; break;

case 'H': getChar = 7; break;

case 'h': getChar = 7; break;

case 'I': getChar = 8; break;

case 'i': getChar = 8; break;

case 'J': getChar = 9; break;

case 'j': getChar = 9; break;

case 'K': getChar = 10; break;

case 'k': getChar = 10; break;

case 'L': getChar = 11; break;

case 'l': getChar = 11; break;

case 'M': getChar = 12; break;

case 'm': getChar = 12; break;

case 'N': getChar = 13; break;

case 'n': getChar = 13; break;

case 'O': getChar = 14; break;

case 'o': getChar = 14; break;

case 'P': getChar = 15; break;

case 'p': getChar = 15; break;

case 'Q': getChar = 16; break;

case 'q': getChar = 16; break;

case 'R': getChar = 17; break;

case 'r': getChar = 17; break;

case 'S': getChar = 18; break;

case 's': getChar = 18; break;

case 'T': getChar = 19; break;

case 't': getChar = 19; break;

case 'U': getChar = 20; break;

case 'u': getChar = 20; break;

case 'V': getChar = 21; break;

case 'v': getChar = 21; break;

case 'W': getChar = 22; break;

case 'w': getChar = 22; break;

case 'X': getChar = 23; break;

case 'x': getChar = 23; break;

case 'Y': getChar = 24; break;

case 'y': getChar = 24; break;

case 'Z': getChar = 25; break;

case 'z': getChar = 25; break;

case ' ': getChar = 26; break;

case '?': getChar = 27; break;  

case '!': getChar = 28; break;

case '£': getChar = 29; break;

case '+': getChar = 30; break;

case '&': getChar = 30; break;

case '.': getChar = 31; break;

case '1': getChar = 32; break;

case '2': getChar = 33; break;

case '3': getChar = 34; break;

case '4': getChar = 35; break;

case '5': getChar = 36; break;

case '6': getChar = 37; break;

case '7': getChar = 38; break;

case '8': getChar = 39; break;

case '9': getChar = 40; break;

case '0': getChar = 41; break;

case ':': getChar = 42; break;

case 39: getChar = 43; break;

}

return getChar;

}

//An array holding the powers of 2 these are used as bit masks when calculating what to display

const int powers[] = {1,2,4,8,16,32,64,128};

//Setup runs once when power is applied

void setup()

{

for(int i = 0; i <8; i++){  //Set the 16 pins used to control the array as OUTPUTs

  pinMode(rowA[i], OUTPUT);

  pinMode(colA[i], OUTPUT);

}

}

 

//repeats  

void loop(){

  if (texton==false){

for (int t=0;t<5;t++){

  data[0] = 255; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 129; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 255; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();

  data[0] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 126; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 126; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();  

data[0] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 60; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 36; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 36; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 60; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();  

  data[0] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 24; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 24; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();

  data[0] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 60; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 36; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 36; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 60; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();

    data[0] = 0; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 126; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 66; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 126; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 0; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite();

   data[0] = 255; //row 1s bit mask (1 LED is on 0 LED is off)

  data[1] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[2] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[3] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[4] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[5] = 129; //row 1s bit mask (1 LED is on 0 LED is off)

  data[6] = 129; //row 1s bit mask (1 LED is on 0 LED is off)  

  data[7] = 255; //row 1s bit mask (1 LED is on 0 LED is off)  

  showSprite(); }texton=true;}

 

  else{

int currentChar = getChar(requestString[index]); ///REFER BACK TO EXTRANEOUS FUNCTION

int nextChar = getChar(requestString[index+1]);

for(int row=0; row < 8; row++){                    //iterate through each row

data[row] = 0;                                   //reset the row we're working on

for(int column=0; column < 8; column++){         //iterate through each column

 data[row] = data[row] + ((powers[column] & (letters[currentChar][row] << offset)));   //loads the current character offset by offset pixels

 data[row] = data[row] + (powers[column] & (letters[nextChar][row] >> (8-offset) ));   //loads the next character offset by offset pixels

}

}

offset++;                                          //increment the offset by one row

if(offset==8){offset = 0; index++; if(index==sizeof(requestString)-2){index=0;texton=false;}}         //if offset is 8 load the next character pair for the next time through

 for(int iii = 0; iii <25; iii++){                 //show the current frame speed

for(int column = 0; column < 8; column++){            // iterate through each column

 for(int i = 0; i < 8; i++){                                            

     digitalWrite(rowA[i], LOW);}                     //turn off all row pins  

 

 for(int i = 0; i < 8; i++){ //set only the one pin

   if(i == column){     digitalWrite(colA[i], LOW);}  //turns the current row on

   else{                digitalWrite(colA[i], HIGH); }}//turns the rest of the rows off

 for(int row = 0; row < 8; row++){                    //iterate through each pixel in the current column

  int bit = (data[column] >> row) & 1;

  if(bit == 1){ //55555555555

     digitalWrite(rowA[row], HIGH);}}                   //if the bit in the data array is set turn the LED on

  delayMicroseconds(pauseDelay);}}  }}                     //leave the column on for pauseDelay microseconds (too high a delay causes flicker)

 

 

 

void showSprite(){

 for(int iii = 0; iii < 20; iii++){                 //show the current frame speed2 times

  for(int column = 0; column < 8; column++){            //iterate through each column

   for(int i = 0; i < 8; i++){                          

       digitalWrite(rowA[i], LOW);}                    //turn off all row pins  

   for(int i = 0; i < 8; i++){ //Set only the one pin

     if(i == column){     digitalWrite(colA[i], LOW);}  //turns the current row on

     else{                digitalWrite(colA[i], HIGH); }}//turns the rest of the rows off

   for(int row = 0; row < 8; row++){                    //iterate through each pixel in the current column

    int bit = (data[column] >> row) & 1;

    if(bit == 1){

       digitalWrite(rowA[row], HIGH);}                  //if the bit in the data array is set turn the LED on

      delayMicroseconds(75);}}  data[0] = 0;}} //row 1s bit mask (1 LED is on 0 LED is off)

                //leave the column on for pauseDelay microseconds (too high a delay causes flicker)

8x8 LED Matrix-Bringing it Together

Go Back

The finale of our study into the LED matrix combines a fusing together of the bitmap animations and text scrolling sketches we looked at in the last chapter. The two are discriminated by a boolean variable switching between true and false, and an if statement comparing this variable to see which animation should be shown.