205
Chapter 18 74HC595 & 7-segment display.
34
35
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
shiftOut
(
dataPin
,
clockPin
,
MSBFIRST
,
data
)
GPIO
.
output
(
latchPin
,
GPIO
.
HIGH
)
d e f
selectDigit
(
digit
):
# Open one of the 7-segment display and close the remaining
three, the parameter digit is optional for 1,2,4,8
GPIO
.
output
(
digitPin
[
0
],
GPIO
.
LOW
i f
( (
digit
&
0x08
)
= =
0x08
)
e l se
GPIO
.
HIGH
)
GPIO
.
output
(
digitPin
[
1
],
GPIO
.
LOW
i f
( (
digit
&
0x04
)
= =
0x04
)
e l se
GPIO
.
HIGH
)
GPIO
.
output
(
digitPin
[
2
],
GPIO
.
LOW
i f
( (
digit
&
0x02
)
= =
0x02
)
e l se
GPIO
.
HIGH
)
GPIO
.
output
(
digitPin
[
3
],
GPIO
.
LOW
i f
( (
digit
&
0x01
)
= =
0x01
)
e l se
GPIO
.
HIGH
)
d e f
display
(
dec
):
#display function for 7-segment display
outData
(
0xff
)
#eliminate residual display
selectDigit
(
0x01
)
#Select the first, and display the single digit
outData
(
num
[
dec
%
10
])
time
.
sleep
(
0.003
)
#display duration
outData
(
0xff
)
selectDigit
(
0x02
)
# Select the second, and display the tens digit
outData
(
num
[
dec
%
100
//
10
])
time
.
sleep
(
0.003
)
outData
(
0xff
)
selectDigit
(
0x04
)
# Select the third, and display the hundreds digit
outData
(
num
[
dec
%
1000
//
100
])
time
.
sleep
(
0.003
)
outData
(
0xff
)
selectDigit
(
0x08
)
# Select the fourth, and display the thousands digit
outData
(
num
[
dec
%
10000
//
1000
])
time
.
sleep
(
0.003
)
d e f
timer
( ):
#timer function
g l obal
counter
g l obal
t
t
=
threading
.
Timer
(
1.0
,
timer
)
#reset time of timer to 1s
t
.
start
()
#Start timing
counter
+=
1
p r int
(
"counter : %d"
%
counter
)
d e f
loop
( ):
g l obal
t
g l obal
counter
t
=
threading
.
Timer
(
1.0
,
timer
)
#set the timer
t
.
start
()
# Start timing
w h ile
T r ue
:
display
(
counter
)
# display the number counter
d e f
destroy
():
# When "Ctrl+C" is pressed, the function is executed.
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 ...