FEAT : Consigne pilote le relais
This commit is contained in:
parent
bff5348031
commit
69c9bf5a53
28
main.py
28
main.py
@ -14,6 +14,7 @@ def debug(str):
|
|||||||
class Bouton:
|
class Bouton:
|
||||||
DEBOUNCE_MS = 500
|
DEBOUNCE_MS = 500
|
||||||
dernier_appui = 0
|
dernier_appui = 0
|
||||||
|
on = False
|
||||||
|
|
||||||
def __init__(self, nom, pin, todo = None, pin_led = None, led_on = False):
|
def __init__(self, nom, pin, todo = None, pin_led = None, led_on = False):
|
||||||
self.nom = nom
|
self.nom = nom
|
||||||
@ -30,10 +31,17 @@ class Bouton:
|
|||||||
def led_on(self):
|
def led_on(self):
|
||||||
if self.avec_led:
|
if self.avec_led:
|
||||||
self.pin_led.on()
|
self.pin_led.on()
|
||||||
|
self.on = True
|
||||||
|
|
||||||
def led_off(self):
|
def led_off(self):
|
||||||
if self.avec_led:
|
if self.avec_led:
|
||||||
self.pin_led.off()
|
self.pin_led.off()
|
||||||
|
self.on = False
|
||||||
|
|
||||||
|
def is_on(self) -> bool:
|
||||||
|
if self.avec_led:
|
||||||
|
return self.on
|
||||||
|
return False
|
||||||
|
|
||||||
def bouton_presse(self, pin):
|
def bouton_presse(self, pin):
|
||||||
self.maintenant = time.ticks_ms()
|
self.maintenant = time.ticks_ms()
|
||||||
@ -152,26 +160,29 @@ relais = Relais()
|
|||||||
cloud = Cloud()
|
cloud = Cloud()
|
||||||
|
|
||||||
def action_jaune():
|
def action_jaune():
|
||||||
|
global consigne
|
||||||
bouton_jaune.led_on()
|
bouton_jaune.led_on()
|
||||||
bouton_bleu.led_off()
|
bouton_bleu.led_off()
|
||||||
bouton_rouge.led_off()
|
bouton_rouge.led_off()
|
||||||
relais.solaire()
|
consigne = 80
|
||||||
|
|
||||||
bouton_jaune = Bouton("jaune", Broche[1], action_jaune, Broche[0], True)
|
bouton_jaune = Bouton("jaune", Broche[1], action_jaune, Broche[0], True)
|
||||||
|
|
||||||
def action_bleu():
|
def action_bleu():
|
||||||
|
global consigne
|
||||||
bouton_jaune.led_off()
|
bouton_jaune.led_off()
|
||||||
bouton_bleu.led_on()
|
bouton_bleu.led_on()
|
||||||
bouton_rouge.led_off()
|
bouton_rouge.led_off()
|
||||||
relais.reseau()
|
consigne = 80
|
||||||
|
|
||||||
bouton_bleu = Bouton("bleu", Broche[3], action_bleu, Broche[2])
|
bouton_bleu = Bouton("bleu", Broche[3], action_bleu, Broche[2])
|
||||||
|
|
||||||
def action_rouge():
|
def action_rouge():
|
||||||
|
global consigne
|
||||||
bouton_jaune.led_off()
|
bouton_jaune.led_off()
|
||||||
bouton_bleu.led_off()
|
bouton_bleu.led_off()
|
||||||
bouton_rouge.led_on()
|
bouton_rouge.led_on()
|
||||||
relais.reseau()
|
consigne = 80
|
||||||
|
|
||||||
bouton_rouge = Bouton("bleu", Broche[10], action_rouge, Broche[9])
|
bouton_rouge = Bouton("bleu", Broche[10], action_rouge, Broche[9])
|
||||||
|
|
||||||
@ -198,8 +209,15 @@ consigne = 80
|
|||||||
while True:
|
while True:
|
||||||
i = (i + 1) % 10
|
i = (i + 1) % 10
|
||||||
print(f"-------------- {i}")
|
print(f"-------------- {i}")
|
||||||
print(f"Charge : {cloud.zoe()}")
|
charge = cloud.zoe()
|
||||||
|
print(f"Charge : {charge}")
|
||||||
print(f"HC : {cloud.HC()}")
|
print(f"HC : {cloud.HC()}")
|
||||||
print(f"Consigne : {consigne}")
|
print(f"Consigne : {consigne}")
|
||||||
leds.afficher(charge=cloud.zoe(), consigne=consigne)
|
leds.afficher(charge = charge, consigne = consigne)
|
||||||
|
if (consigne > charge) and (bouton_bleu.is_on() or bouton_rouge.is_on()):
|
||||||
|
print(f"{consigne} > {charge} On force le réseau")
|
||||||
|
relais.reseau()
|
||||||
|
else:
|
||||||
|
print(f"On force le solaire")
|
||||||
|
relais.solaire()
|
||||||
time.sleep(pas_temps)
|
time.sleep(pas_temps)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user