import uasyncio as asyncio
from machine import Pin
import utime
led_pin = Pin(2,Pin.OUT)
button_pin = Pin(3,Pin.IN)
bottle_count = 0
box_count = 0
emergency_stop = False
async def task1():
global bottle_count, box_count
while True:
if emergency_stop:
break
print("Bottle Count:", bottle_count)
bottle_count += 1
if bottle_count >= 20:
bottle_count = 0
box_count += 1
print("Box Count:", box_count)
utime.sleep(1)
def emergency_button_handler(pin):
global emergency_stop
emergency_stop = not emergency_stop
if emergency_stop:
print("STOP")
blink_led()
else:
print("START")
led_pin.off()
count_bottles()
def blink_led():
while emergency_stop:
led_pin.toggle()
utime.sleep_ms(250)
button_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=emergency_button_handler)
loop = asyncio.get_event_loop()
loop.create_task(task1())
loop.run_forever()