[问题] 关于两个功能只能执行一个

楼主: Kuoluky (kuoluky)   2019-05-29 14:34:33
各位大神好
设计了一个类似手表功能的程式
但由于我是新手
常常设计出来的程式
都只能有一个功能可以使用
程式如下:
import time, RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(16,GPIO.OUT)
GPIO.setup(37,GPIO.IN)
GPIO.setup(40,GPIO.IN)
seg7 = [5, 33, 19, 15, 13, 8, 21, 11]
scan = [23, 31, 29, 3]
font = [0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x27, 0x7F,0x6F, 0x00]
cnt = 0
delaytime = 0.0001
for x in seg7:
GPIO.setup(x, GPIO.OUT)
for x in scan:
GPIO.setup(x, GPIO.OUT)
def out(n):
for x in range(8):
if n % 2 == 1:
GPIO.output(seg7[x], 0)
GPIO.output(12,0)
#if GPIO.input(37) == 0:
#GPIO.output(12, 1)
#else:
#GPIO.output(12,0)
else:
GPIO.output(seg7[x], 1)
n = n // 2
while True:
if GPIO.input(37) == 1:
GPIO.output(12, 1)
ss = int(time.strftime("%M"))
mm = int(time.strftime("%H"))
out(font[ss % 10])
GPIO.output(scan[0], 1)
time.sleep(delaytime)
GPIO.output(scan[0], 0)
temp = ss//10
out(font[temp % 10])
GPIO.output(scan[1], 1)
time.sleep(delaytime)
GPIO.output(scan[1], 0)
out(font[mm % 10] + 128)
GPIO.output(scan[2], 1)
time.sleep(delaytime)
GPIO.output(scan[2], 0)
temp = mm//10
out(font[temp % 10] + 128)
GPIO.output(scan[3], 1)
time.sleep(delaytime)
GPIO.output(scan[3], 0)
GPIO.setwarnings(False)
while cnt <= 9999:
if GPIO.input(40) == 1:
GPIO.output(16, 1)
for x in range(100):
out(font[cnt % 10])
GPIO.output(scan[0], 1)
time.sleep(delaytime)
GPIO.output(scan[0], 0)
temp = cnt // 10
out(font[temp % 10])
GPIO.output(scan[1], 1)
time.sleep(delaytime)
GPIO.output(scan[1], 0)
temp = temp // 10
out(font[temp % 10])
GPIO.output(scan[2], 1)
time.sleep(delaytime)
GPIO.output(scan[2], 0)
temp = temp // 10
out(font[temp % 10])
GPIO.output(scan[3], 1)
time.sleep(delaytime)
GPIO.output(scan[3], 0)
cnt=cnt+1
else:
GPIO.output(16,0)
GPIO.setwarnings(False)
不知道哪里有问题
请大大们帮忙一下,感恩
楼主: Kuoluky (kuoluky)   2019-05-29 14:38:00
程式作动的影片:https://youtu.be/DyRQCbv1cng
作者: froce (froce)   2019-05-29 17:22:00
没仔细看,不过你这到while True就不会出去了吧?
楼主: Kuoluky (kuoluky)   2019-05-29 19:04:00
可是我们第一个功能可以执行...
作者: art1 (人,原来不是人)   2019-05-29 21:18:00
不觉得第二个 while 的位置很怪吗?
楼主: Kuoluky (kuoluky)   2019-05-29 22:02:00
已解决感恩

Links booklink

Contact Us: admin [ a t ] ucptt.com