https://github.com/mnishiguchi/servo_kit
Use PCA9685 PWM/Servo Controller in Elixir
https://github.com/mnishiguchi/servo_kit
elixir nerves pca9685 pwm servo-controller
Last synced: 4 months ago
JSON representation
Use PCA9685 PWM/Servo Controller in Elixir
- Host: GitHub
- URL: https://github.com/mnishiguchi/servo_kit
- Owner: mnishiguchi
- License: mit
- Created: 2020-12-28T01:00:22.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-28T05:09:59.000Z (almost 4 years ago)
- Last Synced: 2024-10-30T21:39:12.683Z (9 months ago)
- Topics: elixir, nerves, pca9685, pwm, servo-controller
- Language: Elixir
- Homepage: https://dev.to/mnishiguchi/controlling-servo-in-elixir-nerves-h47
- Size: 73.2 KB
- Stars: 6
- Watchers: 1
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ServoKit
[](https://hex.pm/packages/servo_kit)
[](https://hexdocs.pm/servo_kit)
Use PCA9685 PWM/Servo Controller in Elixir
## Examples
### Basic usage
```elixir
{:ok, _pid} = ServoKit.start_link()# Set the duty cycle to 7.5% for Channel 0
ServoKit.set_pwm_duty_cycle(7.5, ch: 0)
```### Controling a standard servo
```elixir
ServoKit.start_link()# Define the mapping between the angle in degrees and duty cycle in percentage
angle_range = {0, 180}
duty_cycle_range = {2.5, 12.5}# Set the angle to 0 degree for channel 0
0 |> ServoKit.map(angle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)# Set the angle to 90 degree for channel 0
90 |> ServoKit.map(angle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)# Set the angle to 180 degree for channel 0
180 |> ServoKit.map(angle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)
```### Controling a continuous servo
```elixir
ServoKit.start_link()# Define the mapping between the throttle -1..1 and duty cycle in percentage
throttle_range = {-1.0, 1.0}
duty_cycle_range = {2.5, 12.5}# Stop the actuator for channel 0
0 |> ServoKit.map(throttle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)# Throttle full speed forward for channel 0
1.0 |> ServoKit.map(throttle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)# Throttle full speed reverse for channel 0
-1.0 |> ServoKit.map(throttle_range, duty_cycle_range) |> ServoKit.set_pwm_duty_cycle(ch: 0)
```## Links
- [PCA9685 Overview](https://www.nxp.com/products/power-management/lighting-driver-and-controller-ics/ic-led-controllers/16-channel-12-bit-pwm-fm-plus-ic-bus-led-controller:PCA9685)
- [PCA9685 Data Sheet](https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf)