Servo angle control
This commit is contained in:
parent
f2515c56ce
commit
c6483aceaf
18
src/main.rs
18
src/main.rs
|
@ -1,8 +1,19 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use arduino_hal::port::{Pin, mode::Output};
|
||||
use panic_halt as _;
|
||||
|
||||
const ANGLE_PULSE_RATIO: f32 = 10.25;
|
||||
|
||||
fn set_servo_degree(pin: &mut Pin<Output>, degree: f32) {
|
||||
let delay = (degree * ANGLE_PULSE_RATIO) as u32;
|
||||
pin.set_high();
|
||||
arduino_hal::delay_us(delay);
|
||||
pin.set_low();
|
||||
arduino_hal::delay_us(20000-delay);
|
||||
}
|
||||
|
||||
#[arduino_hal::entry]
|
||||
fn main() -> ! {
|
||||
let dp = arduino_hal::Peripherals::take().unwrap();
|
||||
|
@ -18,12 +29,9 @@ fn main() -> ! {
|
|||
* examples available.
|
||||
*/
|
||||
|
||||
let mut servo = pins.d9.into_output();
|
||||
let mut servo = pins.d9.into_output().downgrade();
|
||||
|
||||
loop {
|
||||
servo.set_high();
|
||||
arduino_hal::delay_us(1450);
|
||||
servo.set_low();
|
||||
arduino_hal::delay_us(18550);
|
||||
set_servo_degree(&mut servo, 180.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue