from microbit import sleep, i2c, button_a, button_b
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)

#Set the initial angle of servo 2(the base rotates the servo,channel 5)
s2.position(5, 30)
sleep(200)

while True:
    if button_a.is_pressed():
        for num in range(30 , 150):
            num += 1
            s2.position(5, num)
            sleep(20)
    if button_b.is_pressed():
        for num in range(30 , 150):
            num += 1
            s2.position(5, 180-num)
            sleep(20)
