ServoKit
Drive PCA9685 PWM/Servo Controller using Elixir
Installation
You can install this library by adding servo_kit
to your list of dependencies in mix.exs
:
def deps do
[
{:servo_kit, "~> 0.0.8"}
]
end
Examples
Dimming an LED
# Initialize a driver.
driver = ServoKit.PCA9685.new(%{i2c_bus_name: "i2c-1", frequency: 50})
# Set the duty cycle to 66.6% for Channel 15.
ServoKit.PCA9685.set_pwm_duty_cycle(driver, 15, 66.6)
Controling a standard servo
# Initialize a standard servo controller.
pid = ServoKit.init_standard_servo(%{
duty_cycle_minmax: {2.5, 12.5},
angle_max: 180
})
# Set the angle to 180 degrees for Channel 0.
ServoKit.set_angle(pid, 0, 180)
Controling a continuous servo
# Initialize a continuous servo controller.
pid = ServoKit.init_continuous_servo(%{
duty_cycle_minmax: {2.5, 12.5},
# A duty cycle in percent at which the servo stops its movement.
duty_cycle_mid: 7.5
})
# Throttle full forward for Channel 8.
ServoKit.set_throttle(pid, 8, 1)
# Throttle full reverse for Channel 8.
ServoKit.set_throttle(pid, 8, -1)
# Stop the movement for Channel 8.
ServoKit.set_throttle(pid, 8, 0)