[問題] 關於兩個功能只能執行一個
各位大神好
設計了一個類似手錶功能的程式
但由於我是新手
常常設計出來的程式
都只能有一個功能可以使用
程式如下:
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)
不知道哪裡有問題
請大大們幫忙一下,感恩
--
Sent from my Windows
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.96.50
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1559111675.A.110.html
→
05/29 14:38,
5年前
, 1F
05/29 14:38, 1F
→
05/29 17:22,
5年前
, 2F
05/29 17:22, 2F
→
05/29 19:04,
5年前
, 3F
05/29 19:04, 3F
推
05/29 21:18,
5年前
, 4F
05/29 21:18, 4F
→
05/29 22:02,
5年前
, 5F
05/29 22:02, 5F