Maj bouton
This commit is contained in:
49
composants/byPanda/bouton.py
Normal file
49
composants/byPanda/bouton.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time as t
|
||||
from septsegments import afficher_temperature
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
|
||||
bouton_up = 23
|
||||
bouton_down = 24
|
||||
GPIO.setup(bouton_up, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(bouton_down, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
def test_boutons():
|
||||
temperature = 18
|
||||
|
||||
|
||||
etatPrecedent_up = GPIO.input(bouton_up)
|
||||
etatPrecedent_down = GPIO.input(bouton_down)
|
||||
|
||||
print("Test lancé ! Appuie sur UP (23) pour monter, DOWN (24) pour descendre.")
|
||||
|
||||
while True:
|
||||
etat_up = GPIO.input(bouton_up)
|
||||
etat_down = GPIO.input(bouton_down)
|
||||
if etat_up != etatPrecedent_up:
|
||||
if etat_up == 0:
|
||||
print("Bouton UP Appuyé ⬆️")
|
||||
temperature += 1
|
||||
if temperature >= 40:
|
||||
temperature = 40
|
||||
afficher_temperature(21,temperature)
|
||||
etatPrecedent_up = etat_up
|
||||
if etat_down != etatPrecedent_down:
|
||||
if etat_down == 0:
|
||||
print("Bouton DOWN Appuyé ⬇️")
|
||||
temperature -= 1
|
||||
if temperature <= 0:
|
||||
temperature = 0
|
||||
afficher_temperature(21,temperature)
|
||||
etatPrecedent_down = etat_down
|
||||
|
||||
t.sleep(0.05)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
test_boutons()
|
||||
except KeyboardInterrupt:
|
||||
print("\nFin du test")
|
||||
GPIO.cleanup()
|
||||
@@ -1,16 +1,18 @@
|
||||
import tm1637
|
||||
import time as t
|
||||
|
||||
# Le TM1637 utilise le mode BCM en arrière-plan
|
||||
|
||||
display = tm1637.TM1637(clk=4, dio=17)
|
||||
display.brightness(2)
|
||||
|
||||
def afficher_temperature(temperature):
|
||||
def afficher_temperature(temperature,temperature_moyenne):
|
||||
print(f"Test affichage: {temperature}")
|
||||
try:
|
||||
temp_entiere = int(temperature)
|
||||
texte_ecran = f"{temp_entiere} C"
|
||||
texte_ecran = f"{temp_entiere}{temperature_moyenne}"
|
||||
display.show(texte_ecran)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Erreur d'affichage : {e}")
|
||||
print(f"Erreur d'affichage : {e}")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user