From 4985906a8cd09fbc32a189413e6cae3e075925f4 Mon Sep 17 00:00:00 2001 From: thepenguin Date: Thu, 23 Mar 2023 22:37:43 +0100 Subject: [PATCH] Now sends message on button press with debounce and toggle --- main.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b48f27e..33adec8 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ import usocket as socket import ssl +from machine import Pin +import time with open('token') as f: token = f.readline().strip('\n') @@ -48,9 +50,20 @@ Content-Length: {content_length}\r s.close() +def simple_msg(): + send_msg("Hello there from the button") def main(): - send_msg("Hello there") - + p2 = Pin(2, Pin.IN) + while True: + cur_value = p2.value() + active = 0 + while active < 20: + if p2.value() != cur_value: + active += 1 + else: + active = 0 + time.sleep_ms(1) + simple_msg() main()