Giter Site home page Giter Site logo

esp-idf-servo's Introduction

ESP IDF Servo Library

Introduction

This crate is a simple wrapper over the esp-idf-sys bindings to make servo control easier using the LEDC module.

Basic Usage

Create a basic Servo Configuration - this one specific for the SG90 series of servo motors.

let peripherals = Peripherals::take().unwrap();

let servo_cfg = ServoConfig {
    // below are servo specific configurations
    max_angle: 180,
    min_width_us: 500,
    max_width_us: 2500,
    frequency: 50,
    
    // choose your timer: see https://esp-rs.github.io/esp-idf-sys/esp_idf_sys/?search=ledc_timer_t_LEDC_TIMER_0
    timer_number: 0,

    // whichever pin the servo is attached to
    pin: 5,

    // the channel number: see https://esp-rs.github.io/esp-idf-sys/esp_idf_sys/type.ledc_channel_t.html
    channel: 0,

    // the speed mode: see https://esp-rs.github.io/esp-idf-sys/esp_idf_sys/constant.ledc_mode_t_LEDC_LOW_SPEED_MODE.html
    speed_mode: 0,
};

Initialize the servo:

let servo = Servo::init(servo_cfg);

Change the angle of the servo within your program:

loop {
    for i in 0..180 {

        servo.write_angle((i as f64));

        FreeRtos::delay_ms(20);

        println!("Angle: {}", servo.read_angle());
    }

    for i in (0..180).rev() {
            
        servo.write_angle((i as f64));

        FreeRtos::delay_ms(20);
        
        println!("Angle: {}", servo.read_angle());
    }
}

esp-idf-servo's People

Contributors

ilikepi63 avatar thedevleon avatar nmandery avatar

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.