数码管动态扫描显示
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 36 37 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import tkinter as tk from tkinter import Label button3 = Button(16) button2 = Button(20) button4 = Button(21) button1 = Button(26) DM = LEDBoard(2, 3, 4, 14, 17,27,22,24,active_high=False)#段码是所有数码管共享 PX = LEDBoard(7,8,9,11,active_high=False) M7G= [ (0, 0, 0, 0, 0,0, 0,0), (1, 1, 1, 1,1, 1,0,0), (0, 1, 1, 0, 0,0, 0,0), (1, 1, 0, 1, 1,0, 1,0), (1, 1, 1, 1,0, 0,1,0), (0, 1, 1, 0,0, 1,1,0), (1, 0, 1, 1,0, 1,1,0), (1, 0, 1, 1,1, 1,1,0), (1, 1, 1, 0,0, 0,0,0), (1, 1, 1, 1,1, 1,1,0), (1, 1, 1, 1,0, 1,1,0), ] Led_Buf =[1,5,3,4] while True : for n in range(0,4) : PX.off()#消隐 DM.value = M7G[Led_Buf[n]+1] PX[n].on() sleep(1/(50*4))#75HZ #sleep(0.02) |
数码管定时器动态扫描显示
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 36 37 38 39 40 41 42 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import threading DM = LEDBoard(2, 3, 4, 14, 17,27,22,24,active_high=False) PX = LEDBoard(7,8,9,11,active_high=False) M7G= [ (0, 0, 0, 0, 0,0, 0,0), (1, 1, 1, 1,1, 1,0,0), (0, 1, 1, 0, 0,0, 0,0), (1, 1, 0, 1, 1,0, 1,0), (1, 1, 1, 1,0, 0,1,0), (0, 1, 1, 0,0, 1,1,0), (1, 0, 1, 1,0, 1,1,0), (1, 0, 1, 1,1, 1,1,0), (1, 1, 1, 0,0, 0,0,0), (1, 1, 1, 1,1, 1,1,0), (1, 1, 1, 1,0, 1,1,0), ] Led_Buf =[1,2,3,4] n=0 def fun_timer(): #print('Hello Timer!') global n PX.off()#消隐 DM.value = M7G[Led_Buf[n]+1] PX[n].on() #sleep(1/(75*4))#75HZ n+=1 n&=3 timer = threading.Timer((1/(75*4)), fun_timer) timer.start() timer = threading.Timer(1, fun_timer) timer.start() while True: Led_Buf[0] +=1 Led_Buf[0] = Led_Buf[0]%10 sleep (1) |