Code Monkey home page Code Monkey logo

servo_kit's Introduction

ServoKit

Hex.pm API docs CI

Use PCA9685 PWM/Servo Controller in Elixir

Examples

Basic usage

{: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

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

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

servo_kit's People

Contributors

mnishiguchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

servo_kit's Issues

Does not work with chained boards

I'm trying to use this with two chained PCA9685 boards. Only the most recently initialized address receives and executes commands.

I've determined that it's because of how reset is called during the init function. This resets the whole bus which causes all the previously initialized boards to stop working.

Simply removing the reset call seems to fix it for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.