FEAT : Classe Leds avec gestion de la consigne
This commit is contained in:
parent
3e206ebcfd
commit
bff5348031
77
main.py
77
main.py
@ -110,12 +110,43 @@ class Cloud:
|
|||||||
print("Erreur :", e)
|
print("Erreur :", e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
class Leds:
|
||||||
|
brightness = 0.01 # 1 %
|
||||||
|
pin_leds = Pin(Broche[8], Pin.OUT)
|
||||||
|
np = NeoPixel(pin_leds, 10)
|
||||||
|
vert = (0, 255, 0)
|
||||||
|
noir = (0, 0, 0)
|
||||||
|
orange = (255, 165, 0)
|
||||||
|
bascule = False
|
||||||
|
|
||||||
|
def _led(self, i, r, g, b):
|
||||||
|
self.np[i] = (
|
||||||
|
int(r * self.brightness),
|
||||||
|
int(g * self.brightness),
|
||||||
|
int(b * self.brightness)
|
||||||
|
)
|
||||||
|
|
||||||
|
def afficher(self, charge:int, consigne):
|
||||||
|
self.bascule = not self.bascule
|
||||||
|
nb_dizaine = charge // 10
|
||||||
|
led_consigne = (consigne // 10) - 1
|
||||||
|
for led in range(0, 10):
|
||||||
|
self._led(led, *self.noir)
|
||||||
|
for led in range(0, nb_dizaine):
|
||||||
|
self._led(led, *self.vert)
|
||||||
|
if self.bascule:
|
||||||
|
self._led(nb_dizaine, *self.vert)
|
||||||
|
else:
|
||||||
|
self._led(led_consigne, *self.orange)
|
||||||
|
self.np.write()
|
||||||
|
|
||||||
|
# x = charge // 10
|
||||||
|
# print(f"--> {x}")
|
||||||
|
# pass
|
||||||
|
|
||||||
# Capter exception pour éviter les sorties intempestives (comme timeout sur ntp)
|
# Capter exception pour éviter les sorties intempestives (comme timeout sur ntp)
|
||||||
# Regarder https://docs.micropython.org/en/latest/esp32/quickref.html#timers
|
# Regarder https://docs.micropython.org/en/latest/esp32/quickref.html#timers
|
||||||
|
|
||||||
# led_jaune = Pin(0, Pin.OUT) # D0
|
|
||||||
# button_jaune = Pin(1, Pin.IN, Pin.PULL_UP) # D1
|
|
||||||
|
|
||||||
relais = Relais()
|
relais = Relais()
|
||||||
|
|
||||||
cloud = Cloud()
|
cloud = Cloud()
|
||||||
@ -144,41 +175,31 @@ def action_rouge():
|
|||||||
|
|
||||||
bouton_rouge = Bouton("bleu", Broche[10], action_rouge, Broche[9])
|
bouton_rouge = Bouton("bleu", Broche[10], action_rouge, Broche[9])
|
||||||
|
|
||||||
button_moins = Pin(16, Pin.IN, Pin.PULL_UP) # D6 (et masse)
|
def action_moins():
|
||||||
button_plus = Pin(17, Pin.IN, Pin.PULL_UP) # D7 (et masse)
|
global consigne
|
||||||
|
consigne = max(10, consigne - 10)
|
||||||
|
|
||||||
bouton_moins = Bouton("moins", Broche[7])
|
bouton_moins = Bouton("moins", Broche[7], action_moins)
|
||||||
|
|
||||||
bouton_plus = Bouton("plus", Broche[6])
|
def action_plus():
|
||||||
|
global consigne
|
||||||
|
consigne = min(100, consigne + 10)
|
||||||
|
|
||||||
|
bouton_plus = Bouton("plus", Broche[6], action_plus)
|
||||||
|
|
||||||
|
leds = Leds()
|
||||||
|
|
||||||
#######################################################""
|
#######################################################""
|
||||||
|
|
||||||
brightness = 0.01 # 1 %
|
|
||||||
|
|
||||||
def set_pixel(i, r, g, b):
|
|
||||||
np[i] = (
|
|
||||||
int(r * brightness),
|
|
||||||
int(g * brightness),
|
|
||||||
int(b * brightness)
|
|
||||||
)
|
|
||||||
|
|
||||||
pin_leds = Pin(19, Pin.OUT) # D8
|
|
||||||
np = NeoPixel(pin_leds, 10)
|
|
||||||
set_pixel(0, 0, 255, 0)
|
|
||||||
set_pixel(7, 0, 255, 0)
|
|
||||||
np.write()
|
|
||||||
# np.brightness(50)
|
|
||||||
|
|
||||||
pas_temps = 1
|
pas_temps = 1
|
||||||
i = 0
|
i = 0
|
||||||
|
consigne = 80
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# now = datetime.now()
|
i = (i + 1) % 10
|
||||||
# print("Date et heure :", now)
|
|
||||||
i += 1
|
|
||||||
print(f"-------------- {i}")
|
print(f"-------------- {i}")
|
||||||
print(f"Charge : {cloud.zoe()}")
|
print(f"Charge : {cloud.zoe()}")
|
||||||
print(f"HC : {cloud.HC()}")
|
print(f"HC : {cloud.HC()}")
|
||||||
|
print(f"Consigne : {consigne}")
|
||||||
|
leds.afficher(charge=cloud.zoe(), consigne=consigne)
|
||||||
time.sleep(pas_temps)
|
time.sleep(pas_temps)
|
||||||
# set_pixel(0, 0, 0, 0) # OFF
|
|
||||||
# np.write()
|
|
||||||
Loading…
Reference in New Issue
Block a user