cybertail/src/main.rs

38 lines
972 B
Rust

#![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();
let pins = arduino_hal::pins!(dp);
/*
* For examples (and inspiration), head to
*
* https://github.com/Rahix/avr-hal/tree/main/examples
*
* NOTE: Not all examples were ported to all boards! There is a good chance though, that code
* for a different board can be adapted for yours. The Arduino Uno currently has the most
* examples available.
*/
let mut servo = pins.d9.into_output().downgrade();
loop {
set_servo_degree(&mut servo, 180.0);
}
}