EasyManua.ls Logo

Freenove Ultimate Starter Kit

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...
205
Chapter 18 74HC595 & 7-segment display.
www.freenove.com
support@freenove.com
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)
def 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 if ((digit&0x08) == 0x08) else GPIO.HIGH)
GPIO. output(digitPin[1],GPIO.LOW if ((digit&0x04) == 0x04) else GPIO.HIGH)
GPIO. output(digitPin[2],GPIO.LOW if ((digit&0x02) == 0x02) else GPIO.HIGH)
GPIO. output(digitPin[3],GPIO.LOW if ((digit&0x01) == 0x01) else GPIO.HIGH)
def 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)
def timer(): #timer function
g lobal counter
g lobal t
t = threading.Timer(1.0,timer) #reset time of timer to 1s
t. start() #Start timing
counter+=1
p rint ("counter : %d"%counter)
def loop():
g lobal t
g lobal counter
t = threading.Timer(1.0,timer) #set the timer
t. start() # Start timing
w hile Tr ue:
display(counter) # display the number counter
def destroy(): # When "Ctrl+C" is pressed, the function is executed.

Table of Contents