58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import machine, time, _thread
|
|
from machine import Timer
|
|
from machine import Pin, I2C
|
|
from i2c_lcd import lcd
|
|
|
|
i2c = I2C(0, scl = Pin(9), sda = Pin(8), freq = 400000)
|
|
|
|
display = lcd(i2c)
|
|
|
|
#led interne du raspberry pico
|
|
pico_led = machine.Pin(25, machine.Pin.OUT)
|
|
|
|
# Objet compte à rebours
|
|
class CptRebours():
|
|
#constructeur, initialise timeleft
|
|
def __init__(self, t=0):
|
|
self.timeleft = t
|
|
# fct callbackappelée par le timer
|
|
def countdown(self, tm):
|
|
if self.timeleft > 0 :
|
|
self.timeleft -= 1
|
|
|
|
# Fonction exécutée dans le second thread
|
|
# gère le clignotement de la led
|
|
def thread_anim():
|
|
while True:
|
|
if (cptr.timeleft>0):
|
|
# fait clignoter la led interne
|
|
pico_led.toggle()
|
|
display.home()
|
|
display.write("Temp = ")
|
|
# attente supplémentaire s'il reste plus de 5s
|
|
if cptr.timeleft>5:
|
|
time.sleep(0.18)
|
|
else:
|
|
# extinction de la led interne
|
|
pico_led.value(0)
|
|
# temps d'attente clignotement
|
|
time.sleep(0.18)
|
|
|
|
#initialisation d'un compte à rebours
|
|
cptr = CptRebours()
|
|
|
|
#démarrage du thread d'animation
|
|
_thread.start_new_thread(thread_anim, ())
|
|
|
|
#boucle du thread principal
|
|
while True:
|
|
cptr = CptRebours(int(input("Compte à rebours en secondes: ")))
|
|
print('Démarrage compte à rebours ...')
|
|
tim = Timer(period=1000, callback=cptr.countdown)
|
|
|
|
while (cptr.timeleft > 0 ):
|
|
print('temps restant:', cptr.timeleft, ' secondes')
|
|
time.sleep(1)
|
|
|
|
print("BIP BIP BIP compte à rebours terminé !")
|
|
tim.deinit() #stoppe et libère le timer |