pub struct Servo<'a, S: TimerSpeed> {
pub duty_range: Range<f32>,
/* private fields */
}Fields§
§duty_range: Range<f32>Valid duty cycle range in absolute values (e.g., 102..491 for SG90 with 12-bit). This corresponds to the pulse width range of the servo.
Implementations§
Source§impl<'d, S: TimerSpeed> Servo<'d, S>
impl<'d, S: TimerSpeed> Servo<'d, S>
Sourcepub fn new<'a>(
name: &'static str,
config: ServoConfig,
ledc: &mut Ledc<'a>,
timer: &'a Timer<'a, S>,
channel_num: Number,
pin: impl OutputPin + 'a,
) -> Result<Servo<'a, S>, Error>
pub fn new<'a>( name: &'static str, config: ServoConfig, ledc: &mut Ledc<'a>, timer: &'a Timer<'a, S>, channel_num: Number, pin: impl OutputPin + 'a, ) -> Result<Servo<'a, S>, Error>
Creates new servo driver instance for LEDC channel.
§Arguments
name- Name identifier for the servo (for logging)config- Servo configurationledc- LEDC peripheral instancetimer- Configured timer instance (useServoConfig::configure_timerto create it)channel_num- Channel number (e.g.,channel::Number::Channel0)pin- GPIO pin to use for PWM output
Sourcepub fn step(&mut self, step_size: f32) -> Result<bool, Error>
pub fn step(&mut self, step_size: f32) -> Result<bool, Error>
Makes step in absolute duty units should be lesser than duty_range().
Return false if servo reaches min or max position.
See also step_pct() for percentage-based stepping.
Note: Step takes some time depending on servo speed.
Sourcepub fn step_pct(&mut self, step_pct: u8) -> Result<bool, Error>
pub fn step_pct(&mut self, step_pct: u8) -> Result<bool, Error>
Makes step in percentage of total range.
Returns false if servo reaches min or max position.
See also step() for absolute duty-based stepping.
Note: Step takes some time depending on servo speed.
Sourcepub fn set_dir(&mut self, dir: Dir) -> Option<Dir>
pub fn set_dir(&mut self, dir: Dir) -> Option<Dir>
Set servo to move new direction. Returns old direction if direction was actually changes.
Sourcepub fn set_angle(&mut self, angle: f32) -> bool
pub fn set_angle(&mut self, angle: f32) -> bool
Sets servo to specified angle in degrees. Note: turn to angle takes some time depending on servo speed.
Sourcepub fn duty_range(&self) -> f32
pub fn duty_range(&self) -> f32
Returns the size of the duty range (difference between max and min duty values). This is not the number of steps, but the range size in duty units.