add piezo

This commit is contained in:
Tomas Krejci 2024-06-21 00:40:27 +02:00
parent 7dee992956
commit ba310c309a

30
main.py
View File

@ -33,6 +33,27 @@ for b in machine.unique_id():
device_id_str = device_id_str[-4:] # Keep last 8 char
device_id = int(device_id_str, 16) # Convert to int from hex in string
### Piezo ###
piezo_pin = machine.Pin(15, machine.Pin.OUT, value=1)
piezo_pin2 = machine.Pin(14, machine.Pin.OUT, value=1)
async def piezo_beep(sec=0.3):
piezo_pin.value(0)
piezo_pin2.value(0)
await asyncio.sleep(sec)
piezo_pin.value(1)
piezo_pin2.value(1)
async def piezo_short_beep():
piezo_pin.value(0)
piezo_pin2.value(0)
await asyncio.sleep(0.1)
piezo_pin.value(1)
piezo_pin2.value(1)
#### Voltage monitor ###
from machine import ADC
from primitives import AADC
@ -99,23 +120,24 @@ async def ble_rx_handler():
try:
if "bomb" in message:
logger.info("BLE: Bomb Explode send to IR")
for i in range(3):
for i in range(5):
asyncio.create_task(
olt_sent_ir(ir_tx, COMMANDS[1][1], COMMANDS[1][2], COMMANDS[1][3])
)
await asyncio.sleep_ms(100)
asyncio.create_task(piezo_beep())
uart.write("BLE: Bomb Explode send to IR\n")
asyncio.create_task(rgb1.set_red())
await asyncio.sleep_ms(100)
while True:
time.sleep_ms(2000)
time.sleep_ms(3000)
logger.info(
"BLE: Bomb Exploded, Device is LOCKED, please restart Device"
)
uart.write(
"BLE: Bomb Exploded, Device is LOCKED\n Please restart Device\n"
)
await piezo_short_beep()
elif "led_on" in message:
logger.info("BLE: LED ON")
@ -256,6 +278,7 @@ async def olt_command(cmd, btn, rgb, ir_tx, tx1, tx2, tx3):
btn.release.clear()
await btn.press.wait()
logger.debug(f"Command {cmd} button pressed")
asyncio.create_task(piezo_short_beep())
await rgb.set_green()
# IR TX send
asyncio.create_task(olt_sent_ir(ir_tx, tx1, tx2, tx3))
@ -351,6 +374,7 @@ async def main(proto):
)
asyncio.create_task(olt_command(command, btn, rgb1, ir_tx, tx1, tx2, tx3))
asyncio.create_task(piezo_short_beep()) # piezo_beep()
### Main loop ###
while True:
await asyncio.sleep(1)