Chapter 19 74HC595 & LED Matrix
218
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
d e f
shiftOut
(
dPin
,
cPin
,
order
,
val
):
f o r
i
i n
range
(
0
,
8
):
GPIO
.
output
(
cPin
,
GPIO
.
LOW
);
i f
(
order
= =
LSBFIRST
):
GPIO
.
output
(
dPin
,(
0x01
&(
val
>>
i
)==
0x01
)
a n d
GPIO
.
HIGH
o r
GPIO
.
LOW
)
e l if
(
order
= =
MSBFIRST
):
GPIO
.
output
(
dPin
,(
0x80
&(
val
<<
i
)==
0x80
)
a n d
GPIO
.
HIGH
o r
GPIO
.
LOW
)
GPIO
.
output
(
cPin
,
GPIO
.
HIGH
);
d e f
loop
( ):
w h ile
T r ue
:
f o r
j
i n
range
(
0
,
500
):
# Repeat enough times to display the smiling face a period
of time
x
=
0x80
f o r
i
i n
range
(
0
,
8
):
GPIO
.
output
(
latchPin
,
GPIO
.
LOW
)
shiftOut
(
dataPin
,
clockPin
,
MSBFIRST
,
pic
[
i
])
#first shift data of line
information to first stage 74HC959
shiftOut
(
dataPin
,
clockPin
,
MSBFIRST
,~
x
)
#then shift data of column
information to second stage 74HC959
GPIO
.
output
(
latchPin
,
GPIO
.
HIGH
)
# Output data of two stage 74HC595 at the
same time
time
.
sleep
(
0.001
)
# display the next column
x
> > =
1
f o r
k
i n
range
(
0
,
len
(
data
)-
8
):
#len(data) total number of "0-F" columns
f o r
j
i n
range
(
0
,
20
):
# times of repeated displaying LEDMatrix in every frame,
the bigger the "j", the longer the display time.
x
=
0x80
# Set the column information to start from the first column
f o r
i
i n
range
(
k
,
k
+
8
):
GPIO
.
output
(
latchPin
,
GPIO
.
LOW
)
shiftOut
(
dataPin
,
clockPin
,
MSBFIRST
,
data
[
i
])
shiftOut
(
dataPin
,
clockPin
,
MSBFIRST
,~
x
)
GPIO
.
output
(
latchPin
,
GPIO
.
HIGH
)
time
.
sleep
(
0.001
)
x
> > =
1
d e f
destroy
():
# When 'Ctrl+C' is pressed, the function is executed.
GPIO
.
cleanup
()
i f
__name__
= =
'__main__'
:
# Program starting from here
p r int
(
'Program is starting...'
)
setup
()
t r y
:
loop
( )
Summary of Contents for Ultimate Starter Kit
Page 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Page 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Page 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Page 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Page 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Page 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...