import tm1637
from machine import Pin, Timer
from utime import sleep
import time
# タイマーモジュール
display = tm1637.TM1637(clk=Pin(0), dio=Pin(1))
# 設定
timer_sec = 5*60
result_min = 0
result_sec = 0
# ミスカウンター
miss = 0
miss_1_Pin = Pin(16, Pin.OUT)
miss_2_Pin = Pin(17, Pin.OUT)
def updateMiss(miss):
miss += 1
if miss == 1:
miss_1_Pin.value(1)
return
elif miss == 2:
miss_2_Pin.value(1)
return
else:
END = True
return
# タイマーモジュール
def resulted(now):
result_min = "0" + str((timer_sec - now) // 60)
result_sec = str((timer_sec - now) % 60)
if len(result_sec) == 1:
result_sec = "0" + result_sec
return [result_min, result_sec]
# キーパット
pad_1_Key = Pin(2, Pin.IN, Pin.PULL_DOWN)
pad_2_Key = Pin(3, Pin.IN, Pin.PULL_DOWN)
pad_3_Key = Pin(4, Pin.IN, Pin.PULL_DOWN)
pad_4_Key = Pin(5, Pin.IN, Pin.PULL_DOWN)
progress = 0
anser = [1, 2, 4, 3]
def pushKeypad(select, miss):
if anser[0] == select and progress == 0:
progress += 1
return True
elif anser[1] == select and progress == 1:
progress += 1
return True
elif anser[2] == select and progress == 2:
progress += 1
return True
elif anser[3] == select and progress == 3:
print("PushKeyPad Clear!!")
return True
else:
updateMiss(miss)
return
# 初期化
now = 0
END = False
# 以下メインループ
while now != timer_sec or END:
t = time.time()
now += 1
r = resulted(now)
# キーパット処理
pushKeypad(pad_1_Key.value(), miss)
pushKeypad(pad_2_Key.value(), miss)
pushKeypad(pad_3_Key.value(), miss)
pushKeypad(pad_4_Key.value(), miss)
print(pad_1_Key.value())
display.numbers(int(r[0]),int(r[1]))
time.sleep(1 - (time.time() - t))
# while True:
# display.numbers(99,99)
# display.numbers(" ")
# time.sleep(1)