I don't understand the use of byte in this code

Hello again everyone.

I posted earlier today with a different question. I’m still just starting with Arduino tinkering and have very limited experience with electronics and programming.

I am using tutorials and small projects to learn and am stuck on an 8x8 matrix tutorial.

I am trying to add new characters to the piece of code below (full tutorial in the pdf attached):

#define display_array_size 8
// ascii 8x8 dot font
#define data_null 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // null char
#define data_ascii_A 0x02,0x0C,0x18,0x68,0x68,0x18,0x0C,0x02 /*"A",0*/
#define data_ascii_B 0x00,0x7E,0x52,0x52,0x52,0x52,0x2C,0x00 /*"B",1*/
#define data_ascii_C 0x00,0x3C,0x66,0x42,0x42,0x42,0x2C,0x00 /*"C",2*/
#define data_ascii_D 0x00,0x7E,0x42,0x42,0x42,0x66,0x3C,0x00 /*"D",3*/
#define data_ascii_E 0x00,0x7E,0x52,0x52,0x52,0x52,0x52,0x42 /*"E",4*/
#define data_ascii_F 0x00,0x7E,0x50,0x50,0x50,0x50,0x50,0x40 /*"F",5*/
#define data_ascii_G 0x00,0x3C,0x66,0x42,0x42,0x52,0x16,0x1E /*"G",6*/
#define data_ascii_H 0x00,0x7E,0x10,0x10,0x10,0x10,0x7E,0x00 /*"H",7*/
#define data_ascii_I 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00 /*"I",8*/
// display array
byte data_ascii[][display_array_size] = {
  data_null,
  data_ascii_A, data_ascii_B,
  data_ascii_C,
  data_ascii_D,
  data_ascii_E,
  data_ascii_F,
  data_ascii_G,
  data_ascii_H,
  data_ascii_I,
};
//the pin to control ROW
const int row1 = 2; // the number of the row pin 24
const int row2 = 3; // the number of the row pin 23
const int row3 = 4; // the number of the row pin 22
const int row4 = 5; // the number of the row pin 21
const int row5 = 17; // the number of the row pin 4
const int row6 = 16; // the number of the row pin 3
const int row7 = 15; // the number of the row pin 2
const int row8 = 14; // the number of the row pin 1
//the pin to control COl
const int col1 = 6; // the number of the col pin 20
const int col2 = 7; // the number of the col pin 19
const int col3 = 8; // the number of the col pin 18
const int col4 = 9; // the number of the col pin 17
const int col5 = 10; // the number of the col pin 16
const int col6 = 11; // the number of the col pin 15
const int col7 = 12; // the number of the col pin 14
const int col8 = 13; // the number of the col pin 13

void displayNum(byte rowNum,int colNum)
{
  int j;
  byte temp = rowNum;
  for(j=2;j<6;j++)
  {
    digitalWrite(j, LOW);
  }
  digitalWrite(row5, LOW);
  digitalWrite(row6, LOW);
  digitalWrite(row7, LOW);
  digitalWrite(row8, LOW);
  for(j=6;j<14;j++)
  {
    digitalWrite(j, HIGH); }
    switch(colNum)
    {
      case 1: digitalWrite(col1, LOW); break;
      case 2: digitalWrite(col2, LOW); break;
      case 3: digitalWrite(col3, LOW); break;
      case 4: digitalWrite(col4, LOW); break;
      case 5: digitalWrite(col5, LOW); break;
      case 6: digitalWrite(col6, LOW); break;
      case 7: digitalWrite(col7, LOW); break;
      case 8: digitalWrite(col8, LOW); break;
      default: break;
    }
    for(j = 1 ;j < 9; j++)
    {
      temp = (0x80)&(temp) ;
      if(temp==0)
      {
        temp = rowNum<<j;
        continue;
      }
      switch(j)
      {
        case 1: digitalWrite(row1, HIGH); break;
        case 2: digitalWrite(row2, HIGH); break;
        case 3: digitalWrite(row3, HIGH); break;
        case 4: digitalWrite(row4, HIGH); break;
        case 5: digitalWrite(row5, HIGH); break;
        case 6: digitalWrite(row6, HIGH); break;
        case 7: digitalWrite(row7, HIGH); break;
        case 8: digitalWrite(row8, HIGH); break;
        default: break;
     }
    temp = rowNum<<j;
  }
}

void setup(){
  int i = 0 ;
  for(i=2;i<18;i++)
  {
    pinMode(i, OUTPUT);
  }

  for(i=2;i<18;i++) {
    digitalWrite(i, LOW);
  }
}
void loop(){
  int t1;
  int l;
  int arrage;
  for(arrage=0;arrage<10;arrage++)
  {
    for(l=0;l<512;l++)
    {
      for(t1=0;t1<8;t1++)
      {
        displayNum(data_ascii[arrage][t1],(t1+1));
      }
    }
  }
}

I understand that I need to use #define and the proper hex values for any new character that I want to insert.
I believe that I need to add the new character name (data_ascii_J for example) in the byte at the begining of the code but I am confused with the syntax.

I read that a byte is a number defined with byte var = val; (with name and value). I also read that the operators allow to access individual elements of a string.

I am not sure what they achieve in the following line though: byte data_ascii[display_array_size] = {

There are numerous aspects of the code below this section that further confuse me but maybe getting some clarity on this will help me progress further.

Can anyone help?

Thanks so much to the all community for the huge amount of support that is available on the forum!

8x8_dot_matrix_mod.pdf (1.06 MB)

You want to define a new character. Have you understood how the existing characters are defined ?

Here, from your tutorial is how A is represented. When it is displayed on the 8 x 8 matrix display, it will be rotated through 90 degrees clockwise.

What character do you want to display ?

Hi 6v6gt,

Thanks for taking the time to help! :smiley:

I believe that I do understand how to define a new character.
I have tried the following lines of code:

#define data_ascii_J 0x00,0x04,0x02,0x42,0x7c,0x40,0x00,0x00

I got the values from this website: Learn on the fly : Online led matrix font generator with binary and hex codes for Arduino

And I do agree. Letters are rotated 90 degrees. It so happened that they are also mirrored (realised this while comparing letters present in the code to the letters from the online generator).
As it stands, it is fine. I understand how letters are being produced and I can work around this. If I was to try and improve the sketch, I would definitely have a look and try to see if I can swap the pins and rows/columns.
At the moment I can work with this and I am trying to understand how the rest of the code functions.

I have also added the line data_ascii_J in

byte data_ascii[][display_array_size]={
  data_null,
  data_ascii_A,
  data_ascii_B,
  data_ascii_C,
  data_ascii_D,
  data_ascii_E,
  data_ascii_F,
  data_ascii_G,
  data_ascii_H,
  data_ascii_I,
  data_ascii_J,
};

And this is where my understanding of the sketch stops.

Going to the end of the code, I have tried to amend the loop without much success, the only thing that brought me closer was changing the initial line:

#define display_array_size 9

By changing the 8 to 9 I do manage to display the last letter, but all letters are offset by one column.

I was trying to deepen my understanding of that line as it looks connected to my issue.

What am I not seeing?
Any further thoughts?