use std::error::Error;
use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;
use rppal::gpio::Gpio;
const GPIO_LED: u8 = 23;
fn main() -> Result<(), Box<dyn Error>> {
let (sender, receiver) = channel();
let led_thread = thread::spawn(move || -> Result<(), rppal::gpio::Error> {
let mut pin = Gpio::new()?.get(GPIO_LED)?.into_output_low();
while let Some(count) = receiver.recv().unwrap() {
println!("Blinking the LED {} times.", count);
for _ in 0u8..count {
pin.set_high();
thread::sleep(Duration::from_millis(250));
pin.set_low();
thread::sleep(Duration::from_millis(250));
}
}
Ok(())
});
sender.send(Some(3))?;
sender.send(None)?;
led_thread.join().unwrap()?;
Ok(())
}