Code
Two 74HC595 are used in this project used, one for controlling columns of LEDMatrix, another for lines. And
two 74HC595 are connected in cascade way (series) and has 16 output port. Because shiftOut () function
output 8-bit data once, twice shiftOut () function are required and data of second stage 74HC595 should be
transmitted preferentially. There are two 74HC595 in this project circuit, A (first stage) and B (second stage).
When the RPi uses shiftOut() function to send data "data1", data of A port will be "data1", and data of B will
be 0. Next, use shiftOut() to send "data2", then data "data1" of A will be moved to B and new data "data2"
will be moved to A. According to the circuit connection, line data should be sent first, then send column data.
The following code will make LEDMatrix display a smiling face, and then display scrolling character "0-F".
C Code 19.1.1 LEDMatrix
First observe the project result, and then analyze the code.
1. Use cd command to enter 19.1.1_LEDMatrix directory of C language.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/19.1.1_LEDMatrix
2. Use following command to compile “LEDMatrix.c” and generate executable file “LEDMatrix”.
gcc LEDMatrix.c -o LEDMatrix -lwiringPi
3. Then run the generated file “LEDMatrix”.
sudo ./LEDMatrix
After the program is executed, LEDMatrix will display a smiling face, and then the display scrolling character
"0-F", circularly.
The following is the program code:
#include <wiringPi.h>
#include <stdio.h>
#include <wiringShift.h>
#define dataPin 0 //DS Pin of 74HC595(Pin14)
#define latchPin 2 //ST_CP Pin of 74HC595(Pin12)
#define clockPin 3 //SH_CP Pin of 74HC595(Pin11)
// data of smiling face
unsigned char pic[ ] ={0x1c,0x22,0x51,0x45,0x45,0x51,0x22,0x1c};
unsigned char data[]={ // data of "0-F"
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " "
0x00, 0x00, 0x3E, 0x41, 0x41, 0x3E, 0x00, 0x00, // "0"
0x00, 0x00, 0x21, 0x7F, 0x01, 0x00, 0x00, 0x00, // "1"
0x00, 0x00, 0x23, 0x45, 0x49, 0x31, 0x00, 0x00, // "2"
0x00, 0x00, 0x22, 0x49, 0x49, 0x36, 0x00, 0x00, // "3"
0x00, 0x00, 0x0E, 0x32, 0x7F, 0x02, 0x00, 0x00, // "4"
0x00, 0x00, 0x79, 0x49, 0x49, 0x46, 0x00, 0x00, // "5"
0x00, 0x00, 0x3E, 0x49, 0x49, 0x26, 0x00, 0x00, // "6"
0x00, 0x00, 0x60, 0x47, 0x48, 0x70, 0x00, 0x00, // "7"
0x00, 0x00, 0x36, 0x49, 0x49, 0x36, 0x00, 0x00, // "8"
0x00, 0x00, 0x32, 0x49, 0x49, 0x3E, 0x00, 0x00, // "9"
0x00, 0x00, 0x3F, 0x44, 0x44, 0x3F, 0x00, 0x00, // "A"