Arduino Byte Array

In this article we are going to display letters and symbol by using byte array

An array of bytes can be very long, sometimes hundreds lines of code. So a good way to keep you code organize is to put the arrays out of the way. In my case with the Arduino IDE I just create a new tab with a name and the extension .h, e.g., filename.h . Then link this file with the main sketch by placing this line on the start of the main sketch e.g., #include "filename.h". It's also possible to read the arrays file from a SD card slot, but you need a microcontroller with SD card slot. For this demonstration we are going to use three arrays of byte only, and they will be placed on the same function. The first array is the letter "I" the second is a heart symbol and third is letter "U". The animation here is the letters and symbol will fall from the back and scroll forward. Since an array of bytes starts from index 0 sometimes you have to manipulate the position of the bytes in the array depending what side you want to start. In this case starts from the bottom of the byte and finish at the top and then comes forward.

void TextSymbolFall() 
{ 
  int mydata,t=120,r=15,g=0,b=15;
  byte I[] = {0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00};               
  byte heart[] = {0x08,0x1C,0x3E,0x7F,0x7F,0x77,0x22,0x00};
  byte U[] = {0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x00}; 
                
    for(int x=0; x<3;x++){
      int iix=7,iixx=8;
      for(int iii=0; iii<8; iii++){
        for(int i=0,ii=iix; i<8,ii<iixx; i++,ii++){
          for(int k=0; k<8; k++){
            if(x==0){mydata = bitRead(I[i],k);}
            if(x==1){mydata = bitRead(heart[i],k);}  
            if(x==2){mydata = bitRead(U[i],k);}     
            LED(ii,7,k,r*mydata,g*mydata,b*mydata);       
          } 
        }
        delay(t);
        clean();
        iix--;
      }
      iix=7;
      for(int iii=0; iii<8; iii++){
        for(int i=0; i<8; i++){
          for(int k=0; k<8; k++){
            if(x==0){mydata = bitRead(I[i],k);}
            if(x==1){mydata = bitRead(heart[i],k);}  
            if(x==2){mydata = bitRead(U[i],k);}     
            LED(i,iix,k,r*mydata,g*mydata,b*mydata);       
          } 
        }
        delay(t);
        iix--;          
      }
      iix=7;
      for(int iii=0; iii<8; iii++){
        for(int i=0; i<8; i++){
          for(int k=0; k<8; k++){
            if(x==0){mydata = bitRead(I[i],k);}
            if(x==1){mydata = bitRead(heart[i],k);}  
            if(x==2){mydata = bitRead(U[i],k);}     
            LED(i,iix,k,0,0,0);       
          } 
        }
        delay(t);
        if(iii==6){delay(500);}
        iix--;
      }
    }  
}

 On top of the function are the variables we need, mydata which will get each bit from the array, time play delay and what color we like to display. Like I mention in the previous article, the value of the color variables will multiply by the result of the mydata variable which will be 0 or 1, so that said 0 is off and 1 is on(15x0=0, 15x1=15). The very first loop (x3) will go around three times for each of the byte array. After that the first three loops block will make the letters and symbol to fall from the top. The middle three loops block will make the letter and symbol to come forward and the last three loops block will turn off everything gradually. The "if" statement on each block of loops determine the sequence of which letter or symbol to play.

CONCLUSION:

This demonstration is a very simple way to display byte text and symbols for beginners like myself. You can download online the whole alphabet and symbols of bytes, but most of the time you still have to manipulate the bytes in the array depending of your animation.      


by: Almir Puglia | 311