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.