import time
from Button import *
from Sensors import *
from Buzzer import *
from Scanner import *
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
s = Scanner()
while True:
print('Testing non-blocking scanner')
x = s.scanData(timeout=5, clear=False)
if x == None:
print('Nothing was scanned')
else:
print(f'You scanned: {x} - hooray')
print()
j = Joystick(hpin=27, vpin=28, swpin=22, name='Joystick')
s = UltrasonicSensor(trigger=20, echo=19)
b = PassiveBuzzer(15)
while True:
status = j.getStatus()
if status != 'Center' and status != 'Moving':
print(f'Joystic status is {status}')
if j.isPressed():
print('Joystick button pressed')
d = s.getDistance()
if d < 300:
b.play()
time.sleep(d/1000)
while s.tripped():
print("Ultrasonic sensor is tripped")
b.stop()
time.sleep(0.2)