# Project objective: Swing the servo arm from min, mid, to max positions
#
# Hardware and connections used:
# Servo GND to Raspberry Pi Pico GND
# Servo V+ to Raspberry Pi Pico 3.3 V
# Servo PWM pin to GPIO Pin 15
#
# Programmer: Adrian Josele G. Quional
# modules
from picozero import Servo # importing Servo class to easily control the servo motor
from time import sleep
from machine import Pin , PWM
# creating a Servo object
servo = Servo(15)
button=Pin(0, Pin.IN ,Pin.PULL_DOWN)
min_duty=1000
max_duty=2000
def set_angle(angle):
duty=min_duty + (max_duty-max_duty)*angle // 180
servo.duty_u16(duty)
# continuously swing the servo arm to min, mid, and max positions (for a duration of 1 sec each)
while True:
if button.value()==1 :
set_angle(45)
sleep(0.5)