In this lesson we demonstrate how to create a custom library on the Raspberry Pi Pico W to control a servo. We create a servo class, and then show how to use it as a library in future programs.
1 2 3 4 5 6 7 8 9 10 | class servo: def __init__(self,sPin): import machine self.servoPin=sPin self.obj=machine.PWM(machine.Pin(self.servoPin)) self.obj.freq(50) def pos(self,angle): writeVal=6553/180*angle+1638 self.obj.duty_u16(int(writeVal)) |