debounce, held

This commit is contained in:
2020-11-30 15:17:19 +01:00
parent 89aed8edeb
commit 4c9723561a

View File

@@ -18,6 +18,7 @@ MQTT_RECEIVE = "buttons/receive"
#variabili globali
isRunning = True
client = None
debounce = 0.25
def on_message(client, userdata, msg):
print(f"{msg.topic} -> {str(msg.payload)}")
@@ -54,12 +55,12 @@ def main():
global client
global isRunning
btn_su = Button(SU)
btn_giu = Button(GIU)
btn_sx = Button(SX)
btn_dx = Button(DX)
btn_ok = Button(OK)
btn_can = Button(CAN)
btn_su = Button(SU, bounce_time=debounce, hold_repeat=True)
btn_giu = Button(GIU, bounce_time=debounce, hold_repeat=True)
btn_sx = Button(SX, bounce_time=debounce, hold_repeat=True)
btn_dx = Button(DX, bounce_time=debounce, hold_repeat=True)
btn_ok = Button(OK, bounce_time=debounce, hold_repeat=True)
btn_can = Button(CAN, bounce_time=debounce, hold_repeat=True)
while isRunning:
try:
@@ -68,12 +69,21 @@ def main():
client.connect('localhost',1883)
client.subscribe(MQTT_RECEIVE)
client.on_message = on_message
#evento premuto
btn_su.when_pressed = send_SU
btn_giu.when_pressed = send_GIU
btn_sx.when_pressed = send_SX
btn_dx.when_pressed = send_DX
btn_ok.when_pressed = send_OK
btn_can.when_pressed = send_CAN
#evento tenuto
btn_su.when_held = send_SU
btn_giu.when_held = send_GIU
btn_sx.when_held = send_SX
btn_dx.when_held = send_DX
btn_ok.when_held = send_OK
btn_can.when_held = send_CAN
while isRunning:
client.loop(timeout=1)
time.sleep(1)