#!/usr/bin/env python3
# rpi_servo_test.py
import time
import board
import busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo

i2c = busio.I2C(board.SCL, board.SDA)
pca = PCA9685(i2c)
pca.frequency = 50

test_servo = servo.Servo(pca.channels[0], min_pulse=1000, max_pulse=2000)

try:
    print("RPI servo sweep ch0")
    while True:
        for a in range(10, 181, 10):
            test_servo.angle = a
            print("ch0:", a)
            time.sleep(0.1)
        for a in range(180, -1, -10):
            test_servo.angle = a
            print("ch0:", a)
            time.sleep(0.1)
except KeyboardInterrupt:
    print("Stopped by user")
finally:
    pca.deinit()

