Register button presses

This commit is contained in:
2020-10-13 11:44:02 -07:00
parent 5b52c6a78e
commit 6d3d0fee0f
2 changed files with 25 additions and 1 deletions

View File

@@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
rppal = "0.11.3"

View File

@@ -1,3 +1,26 @@
use std::thread::sleep;
use std::time::Duration;
use rppal::gpio::{Gpio, Trigger};
const BUTTON_PIN: u8 = 26;
fn main() { 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"); }
}
}
} }