rahul-thakoor / rust_gpiozero

A library inspired by gpiozero written in Rust
https://crates.io/crates/rust_gpiozero
Apache License 2.0
232 stars 27 forks source link

GPIO still on after program exit #7

Closed hasanAjsf closed 4 years ago

hasanAjsf commented 5 years ago

Hi,

I just wrote my first prgram:

use rust_gpiozero::*;
use std::thread::sleep;
use std::time::Duration;

fn main() {
    let mut yellow = LED::new(21);
    let mut red = LED::new(26);
    loop{
       red.on();
       yellow.off();
       sleep(Duration::from_millis(200));
        yellow.on();
        sleep(Duration::from_millis(200));
        red.off();
        sleep(Duration::from_millis(200));
    }
}

Once pressing Ctrl+C the program is exit but the Led still on, even if I removed the wire and returned it, to the GPIO it still on!

rahul-thakoor commented 5 years ago

hey there, Given that Rust doesn't catch ctrl-c or SIGTERM, you can use simple signal to handle those.

You can check the example here and adapt it for your code