Compare commits
No commits in common. "69c9bf5a538bb387640dea24464fbb66c78293d6" and "3e206ebcfd3fab398d18dc16b23795e1e1738bfc" have entirely different histories.
69c9bf5a53
...
3e206ebcfd
103
main.py
103
main.py
@ -14,7 +14,6 @@ def debug(str):
|
||||
class Bouton:
|
||||
DEBOUNCE_MS = 500
|
||||
dernier_appui = 0
|
||||
on = False
|
||||
|
||||
def __init__(self, nom, pin, todo = None, pin_led = None, led_on = False):
|
||||
self.nom = nom
|
||||
@ -31,17 +30,10 @@ class Bouton:
|
||||
def led_on(self):
|
||||
if self.avec_led:
|
||||
self.pin_led.on()
|
||||
self.on = True
|
||||
|
||||
def led_off(self):
|
||||
if self.avec_led:
|
||||
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):
|
||||
self.maintenant = time.ticks_ms()
|
||||
@ -118,106 +110,75 @@ class Cloud:
|
||||
print("Erreur :", e)
|
||||
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)
|
||||
# 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()
|
||||
|
||||
cloud = Cloud()
|
||||
|
||||
def action_jaune():
|
||||
global consigne
|
||||
bouton_jaune.led_on()
|
||||
bouton_bleu.led_off()
|
||||
bouton_rouge.led_off()
|
||||
consigne = 80
|
||||
relais.solaire()
|
||||
|
||||
bouton_jaune = Bouton("jaune", Broche[1], action_jaune, Broche[0], True)
|
||||
|
||||
def action_bleu():
|
||||
global consigne
|
||||
bouton_jaune.led_off()
|
||||
bouton_bleu.led_on()
|
||||
bouton_rouge.led_off()
|
||||
consigne = 80
|
||||
relais.reseau()
|
||||
|
||||
bouton_bleu = Bouton("bleu", Broche[3], action_bleu, Broche[2])
|
||||
|
||||
def action_rouge():
|
||||
global consigne
|
||||
bouton_jaune.led_off()
|
||||
bouton_bleu.led_off()
|
||||
bouton_rouge.led_on()
|
||||
consigne = 80
|
||||
relais.reseau()
|
||||
|
||||
bouton_rouge = Bouton("bleu", Broche[10], action_rouge, Broche[9])
|
||||
|
||||
def action_moins():
|
||||
global consigne
|
||||
consigne = max(10, consigne - 10)
|
||||
button_moins = Pin(16, Pin.IN, Pin.PULL_UP) # D6 (et masse)
|
||||
button_plus = Pin(17, Pin.IN, Pin.PULL_UP) # D7 (et masse)
|
||||
|
||||
bouton_moins = Bouton("moins", Broche[7], action_moins)
|
||||
bouton_moins = Bouton("moins", Broche[7])
|
||||
|
||||
def action_plus():
|
||||
global consigne
|
||||
consigne = min(100, consigne + 10)
|
||||
|
||||
bouton_plus = Bouton("plus", Broche[6], action_plus)
|
||||
|
||||
leds = Leds()
|
||||
bouton_plus = Bouton("plus", Broche[6])
|
||||
|
||||
#######################################################""
|
||||
|
||||
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
|
||||
i = 0
|
||||
consigne = 80
|
||||
|
||||
while True:
|
||||
i = (i + 1) % 10
|
||||
# now = datetime.now()
|
||||
# print("Date et heure :", now)
|
||||
i += 1
|
||||
print(f"-------------- {i}")
|
||||
charge = cloud.zoe()
|
||||
print(f"Charge : {charge}")
|
||||
print(f"Charge : {cloud.zoe()}")
|
||||
print(f"HC : {cloud.HC()}")
|
||||
print(f"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)
|
||||
# set_pixel(0, 0, 0, 0) # OFF
|
||||
# np.write()
|
||||
Loading…
Reference in New Issue
Block a user