Browse Source

Add delay before publishing brightness change

master
arofarn 2 years ago
parent
commit
343722086b
  1. 11
      code/main.py

11
code/main.py

@ -209,6 +209,7 @@ MqttMultiPublish(data)
time.sleep(1)
BRIGHTN_DATA = None
while True:
@ -217,8 +218,9 @@ while True:
if BRIGHTN != ENCODER.value:
print(ENCODER.value)
BRIGHTN = ENCODER.value
MqttMultiPublish([['brightness/date', now(rtc), True, 1],
['brightness/value', "{}".format(BRIGHTN), True, 0]])
MQTT_TIMER = time.ticks_add(time.ticks_ms(), MQTT_DELAY * 1000)
BRIGHTN_DATA = [['brightness/date', now(rtc), True, 1],
['brightness/value', "{}".format(BRIGHTN), True, 0]]
# Mise à jour des LED
light_modes.update_neopixel(CURRENT_MODE,
@ -232,3 +234,8 @@ while True:
PWR, CURRENT_MODE)
BUTTN_STATE = ENC_BUT.value()
# On n'envoie les données de luminosité qu'une fois stabilisée (MQTT_DELAY)
if BRIGHTN_DATA is not None and time.ticks_diff(time.ticks_ms(), MQTT_TIMER) >= 0:
MqttMultiPublish(BRIGHTN_DATA)
BRIGHTN_DATA = None

Loading…
Cancel
Save