EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 217

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
217
Chapter 19 74HC595 & LED Matrix
www.freenove.com
support@freenove.com
Python 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 Python language.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/19.1.1_LEDMatrix
2. Use python command to execute python code “LEDMatrix.py”.
python LEDMatrix.py
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
im port RPi. GPIO as GPIO
im port time
LSBFIRST = 1
MSBFIRST = 2
#define the pins connect to 74HC595
dataPin = 11 #DS Pin of 74HC595(Pin14)
latchPin = 13 #ST_CP Pin of 74HC595(Pin12)
clockPin = 15 #SH_CP Pin of 74HC595(Pin11)
pic = [0x1c,0x22,0x51,0x45,0x45,0x51,0x22,0x1c]# data of smiling face
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"
0x00, 0x00, 0x7F, 0x49, 0x49, 0x36, 0x00, 0x00, # "B"
0x00, 0x00, 0x3E, 0x41, 0x41, 0x22, 0x00, 0x00, # "C"
0x00, 0x00, 0x7F, 0x41, 0x41, 0x3E, 0x00, 0x00, # "D"
0x00, 0x00, 0x7F, 0x49, 0x49, 0x41, 0x00, 0x00, # "E"
0x00, 0x00, 0x7F, 0x48, 0x48, 0x40, 0x00, 0x00, # "F"
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # " "
]
def setup():
GPIO. setmode(GPIO.BOARD) # Number GPIOs by its physical location
GPIO. setup(dataPin, GPIO. OUT)
GPIO. setup(latchPin, GPIO. OUT)
GPIO. setup(clockPin, GPIO. OUT)

Table of Contents