diff --git a/main.py b/main.py index 6ff2c23..395ce7e 100644 --- a/main.py +++ b/main.py @@ -45,19 +45,19 @@ async def peripheral_task(): except BaseException as e: print("Exception in peripheral_task:", e) -async def read_task(rdr): +async def read_task(rdr, buzzer=None): # Start listening for a card time.sleep_ms(1000) print("Waiting for RFID/NFC card...") while True: try: - do_read(rdr) + do_read(rdr, buzzer) except Exception as e: print("Exception in read_task:", e) await asyncio.sleep_ms(100) -def do_read(rdr): +def do_read(rdr, buzzer=None): gc.collect() last_uid = None while True: @@ -74,6 +74,12 @@ def do_read(rdr): struid = "".join(['{:0>{w}}'.format(hex(i)[2:], w=2) for i in uid]) print("Found card with UID:", struid) rfid_characteristic.write(uid) + + if buzzer: + buzzer.value(1) + time.sleep_ms(300) + buzzer.value(0) + last_uid = uid except Exception as e: print("Something failed:", e) @@ -101,9 +107,12 @@ async def main(): gc.collect() + buzzer = Pin(27, Pin.OUT) + buzzer.value(0) + await asyncio.gather( peripheral_task(), - read_task(pn532) + read_task(pn532, buzzer) ) except KeyboardInterrupt: