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 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause #from gpiozero.pins.pigpio import PiGPIOFactory M7G= [ (1,1,1,1,1,1,0,0),#0 (0,1,1,0,0,0,0,0),#1 (1,1,0,1,1,0,1,0),#2 (1,1,1,1,0,0,1,0),#3 (0,1,1,0,0,1,1,0),#4 (1,0,1,1,0,1,1,0),#5 (1,0,1,1,1,1,1,0),#6 (1,1,1,0,0,0,0,0),#7 (1,1,1,1,1,1,1,0),#8 (1,1,1,1,0,1,1,0),#9 (0,0,0,0,0,0,0,0),#全灭 ] #factory = PiGPIOFactory(host='raspberry00.local') #,pin_factory=factory) DM = LEDBoard(19,11,12,20,21,13,7,16,active_high=False)#,pin_factory=factory) PX = LEDBoard(26,6,5,8,active_high=True)#,pin_factory=factory) while True : DM.value = M7G[1] PX.value = (1,0,0,0) sleep(0.01) DM.value = M7G[2] PX.value = (0,1,0,0) sleep(0.01) |
上述程序中,有余辉存在,思考一下,为何会有这个情况?
感受一下慢动作:
1 2 3 4 5 6 7 8 9 10 |
while True : DM.value = M7G[1] sleep(1) PX.value = (1,0,0,0) sleep(1) DM.value = M7G[2] sleep(1) PX.value = (0,1,0,0) sleep(1) |
所以得出结论,余辉的存在是因为在前一个数码管上显示了后面的数码管段码的缘故。
解决办法:
在显示完成后,增加消隐指令:PX.off()
最后完成程序如下:
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 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause #from gpiozero.pins.pigpio import PiGPIOFactory M7G= [ (1,1,1,1,1,1,0,0),#0 (0,1,1,0,0,0,0,0),#1 (1,1,0,1,1,0,1,0),#2 (1,1,1,1,0,0,1,0),#3 (0,1,1,0,0,1,1,0),#4 (1,0,1,1,0,1,1,0),#5 (1,0,1,1,1,1,1,0),#6 (1,1,1,0,0,0,0,0),#7 (1,1,1,1,1,1,1,0),#8 (1,1,1,1,0,1,1,0),#9 (0,0,0,0,0,0,0,0),#全灭 ] #factory = PiGPIOFactory(host='raspberry00.local') #,pin_factory=factory) DM = LEDBoard(19,11,12,20,21,13,7,16,active_high=False)#,pin_factory=factory) PX = LEDBoard(26,6,5,8,active_high=True)#,pin_factory=factory) while True : DM.value = M7G[1] #sleep(1) PX.value = (1,0,0,0) sleep(0.01) PX.off()#消隐 DM.value = M7G[2] #sleep(1) PX.value = (0,1,0,0) sleep(0.01) PX.off()#消隐 |
转载请注明:徐自远的乱七八糟小站 » 20181017 数码管余辉的产生原因与解决方案