各位大神好
设计了一个类似手表功能的程式
但由于我是新手
常常设计出来的程式
都只能有一个功能可以使用
程式如下:
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)
不知道哪里有问题
请大大们帮忙一下,感恩