# modules
from picozero import Servo # importing Servo class to easily control the servo motor
from time import sleep
from machine import Pin
# creating a Servo object
servo = Servo(18)
# push buttons left and right
push_bt_left = Pin(16, Pin.IN, Pin.PULL_UP)
push_bt_right = Pin(17, Pin.IN, Pin.PULL_UP)
# swinging the servo arm to its mid position
servo.mid()
# continuously swing the servo arm to min, mid, and max positions (for a duration of 1 sec each)
while True:
# swinging the servo arm to its min and max position
if (push_bt_left.value() == 0):
#wait for button to be relased
while (push_bt_left.value() == 0):
sleep(0.05)
servo.value = servo.value-0.05
sleep(0.01)
if (push_bt_right.value() == 0):
#wait for button to be relased
while (push_bt_right.value() == 0):
sleep(0.05)
servo.value = servo.value+0.05
sleep(0.01)
sleep(0.5)