Crates.io | esp-idf-servo |
lib.rs | esp-idf-servo |
version | 0.2.4 |
source | src |
created_at | 2023-06-12 12:36:43.206367 |
updated_at | 2023-06-20 14:19:45.737474 |
description | A wrapper of esp-idf-sys bindings for Servo PWM control |
homepage | |
repository | https://github.com/ilikepi63/esp-idf-servo |
max_upload_size | |
id | 888152 |
size | 7,549 |
This crate is a simple wrapper over the esp-idf-sys
bindings to make servo control easier using the LEDC module.
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());
}
}