Register button presses
This commit is contained in:
@@ -7,3 +7,4 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rppal = "0.11.3"
|
||||
|
||||
25
src/main.rs
25
src/main.rs
@@ -1,3 +1,26 @@
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
use rppal::gpio::{Gpio, Trigger};
|
||||
|
||||
const BUTTON_PIN: u8 = 26;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let gpio = Gpio::new().expect("gpio init");
|
||||
let mut pin = gpio.get(BUTTON_PIN).expect("pin init").into_input_pulldown();
|
||||
|
||||
pin.set_interrupt(Trigger::RisingEdge).expect("set interrupt");
|
||||
|
||||
let mut count = 0;
|
||||
loop {
|
||||
match pin.poll_interrupt(true, Some(Duration::from_secs(5))) {
|
||||
Ok(Some(_)) => {
|
||||
count += 1;
|
||||
println!("pushed: {}", count);
|
||||
sleep(Duration::from_millis(25));
|
||||
},
|
||||
Ok(None) => println!("time"),
|
||||
err => { err.expect("poll"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user