use embedded_hal::digital::v2::OutputPin; use std::thread; use std::time::Duration; pub struct Blink where T: OutputPin, { state: bool, pin: T, stopped: bool, } impl Blink where T: OutputPin, { pub fn new(pin: T) -> Blink { return Blink { state: false, pin, stopped: false, }; } pub fn toggle(&mut self) -> Result<(), T::Error> { self.state = !self.state; if self.state { self.pin.set_high() } else { self.pin.set_low() } } pub fn play(&mut self) where ::Error: std::fmt::Debug { loop { if self.stopped { break; } self.toggle().unwrap(); thread::sleep(Duration::from_millis(10)); self.toggle().unwrap(); thread::sleep(Duration::from_millis(990)); } } }