MarsCar/managed_components/espressif__servo/examples/servo_control
2025-06-30 01:23:50 +08:00
..
main 轮子操控 2025-06-30 01:23:50 +08:00
CMakeLists.txt 轮子操控 2025-06-30 01:23:50 +08:00
README.md 轮子操控 2025-06-30 01:23:50 +08:00

Example for the servo component

This example shows how to use the servo component.

How to use

Initialize the sensor with the configuration:

    servo_config_t servo_cfg = {
        .max_angle = 180,
        .min_width_us = 500,
        .max_width_us = 2500,
        .freq = 50,
        .timer_number = LEDC_TIMER_0,
        .channels = {
            .servo_pin = {
                SERVO_GPIO,
            },
            .ch = {
                LEDC_CHANNEL_0,
            },
        },
        .channel_number = 1,
    };

    // Initialize the servo
    iot_servo_init(LEDC_LOW_SPEED_MODE, &servo_cfg);

Set the angle:

uint16_t angle = 0;
iot_servo_write_angle(LEDC_LOW_SPEED_MODE, 0, angle);