from microbit import sleep, i2c
from PCA9685 import *
from servo import *

# Initialise the PCA9685 using the default address (0x40).
pwm = PCA9685.PCA9685(i2c)

# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)

print('Moving servo on channel 5, press Ctrl-C to quit...')

# Use servo 2 helper class to move channel 5 by degrees
s2 = Servos(i2c)
while True:
    for num in range(30 , 150):
        num += 1
        s2.position(5, num)
        sleep(20)
    for num in range(30 , 150):
        num += 1
        s2.position(5, 180-num)
        sleep(20)
