Beginner Sunfounder 8x8 sketch explanation

Hi all,

This is my first post in the forum. I'm a newbie to Arduino and I purchased the Sunfounder kit to get started. I'm satisfied with everything in the kit, but the theory explanations leave much to be desired. I followed the schematic and uploaded the example sketch for the 8x8 dot matrix, which scrolls through numbers and the first five letters of the alphabet.

It works - with the exception that it's a complete mirror image of the numbers and letters. At any rate, my question is primarily around the sketch itself. I don't understand how it works. More specifically, the letters and numbers in the array "data" make no sense to me. How does this get converted to the displayed characters?

I have a basic understanding of variables, loops, etc. But it's very basic. I'm just not following the logic here. Any help would be appreciated.

Here is the sample code:

const int latchPin = 8;//Pin connected to ST_CP of 74HC595
const int clockPin = 12;//Pin connected to SH_CP of 74HC595
const int dataPin = 11; //Pin connected to DS of 74HC595
int data[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/
              0xFF,0xC1,0xBE,0xBE,0xBE,0xC1,0xFF,0xFF,
              0xFF,0xFF,0xFF,0xFF,0xDF,0xDF,0x80,0xFF,/*"1",2*/
              0xFF,0xDC,0xBC,0xBA,0xB6,0xCE,0xFF,0xFF,/*"2",3*/
              0xFF,0xDD,0xBE,0xB6,0xB6,0xC9,0xFF,0xFF,/*"3",4*/
              0xFB,0xF3,0xEB,0xDB,0x80,0xFB,0xFF,0xFF,/*"4",5*/
              0xFF,0x8D,0xAE,0xAE,0xAE,0xB1,0xFF,0xFF,/*"5",6*/
              0xFF,0xC1,0x96,0xB6,0xB6,0xD9,0xFF,0xFF,/*"6",7*/
              0xFF,0xBF,0xBC,0xB3,0xAF,0x9F,0xFF,0xFF,/*"7",8*/
              0xFF,0xC9,0xB6,0xB6,0xB6,0xC9,0xFF,0xFF,/*"8",9*/
              0xFF,0xCD,0xB6,0xB6,0xB4,0xC1,0xFF,0xFF,/*"9",10*/
              0xFC,0xF3,0xCB,0x9B,0xEB,0xF3,0xFC,0xFF,/*"A",11*/
              0xFF,0x80,0xB6,0xB6,0xB6,0xB6,0xC9,0xFF,/*"B",12*/
              0xFF,0xE3,0xDD,0xBE,0xBE,0xBE,0xBE,0xDD,/*"C",13*/
              0xFF,0x80,0xBE,0xBE,0xBE,0xBE,0xDD,0xE3,/*"D",14*/
              0xFF,0x80,0xB6,0xB6,0xB6,0xB6,0xBE,0xFF,/*"E",15*/
              0xFF,0x80,0xB7,0xB7,0xB7,0xB7,0xBF,0xFF,/*"F",16*/
              0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/};/*"0",1*/
void setup ()
{
  //set pins to output
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);
}
void loop()
{
    for(int n = 0; n < 136; n++)
    {
        for(int t=0;t<100;t++)
        {
            int dat = 0x01;
            for(int num=n; num < 8+n; num++)
            {
                dat = dat<<1;
                shiftOut(dataPin,clockPin,MSBFIRST,~data[num]);
                shiftOut(dataPin,clockPin,MSBFIRST,~dat);
                digitalWrite(latchPin,HIGH);
                //delay(1);
                digitalWrite(latchPin,LOW);
            }
        }
    }
}

with the exception that it's a complete mirror image of the numbers and letters

Maybe try LSBFIRST ?

the Sunfounder kit

?

http://www.amazon.com/SunFounder-Project-Starter-Arduino-Mega2560/dp/B00D9NQDAG/ref=sr_1_2?s=pc&ie=UTF8&qid=1441565905&sr=1-2&keywords=sunfounder+super+kit

I'm sorry, but I don't understand what you mean by the LSBFirst.

I've looked it up, but I still don't understand the theory of the original code.
What do these characters mean? How do they form the letters?

0xFF,0xFF,0xFF,0xFF,0xDF,0xDF,0x80,0xFF

I'm sorry, but I don't understand what you mean by the LSBFirst

It's the opposite of MSBFIRST

It's the opposite of MSBFIRST

I get that, but it doesn't help with my original question...

Why don't you just try it?

How do they form the letters?

Write them out in binary.

The data array holds a couple of bit-patterns (each 8 bytes of 8 bits),
that are expressed in the initialisation by hexadecimal constants.
These patterns are shifted out (bitwise) to the controller chip.
If your pattern looks mirrored, you are probably shifting it out
in the wrong direction as already mentioned (including how to fix it).

I think in the pattern a zero corresponds to lit led.

The pattern also seems to be rotated, look at the pattern for "3":

/"3",4/
0xFF ........
0xDD ......
0xBE ......
0xB6 .....*
0xB6 .....*
0xC9 ....
0xFF ........
0xFF ........

I changed the first MSBFIRST to LSBFIRST and it fixed the mirror.

      shiftOut(dataPin,clockPin,LSBFIRST,~data[num]);
               shiftOut(dataPin,clockPin,MSBFIRST,~dat);

I hate to say this, but you are still talking over my head on the explanation. I can convert the hex to binary, but that is about as far as I can go. I still don't get how that creates the character. If I wanted to create, say the letter M, how would I do this?

Sorry for the stupid questions.

Draw an eight by eight grid.
Write 1s where you want the LED to be lit, in the orientation you want.
Write the value out in hex.

The letter 'M' could be represented by something like:

0xFF --------
0x80 -*******
0xDF --*-----
0xEF ---*----
0xDF --*-----
0x80 -*******
0xFF --------
0xFF --------

OK. Light bulb just turned on! Thank you.

So, I follow that logic. Now when I work it out, the 0's are lit. Not the 1's

 shiftOut(dataPin,clockPin,MSBFIRST,~data[num]);

That's what the ~ does for you.

Thanks for your patience and responses. I'm going to play with this later. May have a few more questions at that point.

Thanks again!

AWOL:

 shiftOut(dataPin,clockPin,MSBFIRST,~data[num]);

That's what the ~ does for you.

So probably removing the tilde ('~') and flipping the bits in the pattern
(by xoring with 0xFF) would speed the transfer up (only a tiny bit),
make the sketch smaller (also a tiny bit)
and make the patterns more readable, at least for me.