Created
September 11, 2024 08:21
-
-
Save manio/b612d5a16d3acd7a17eccda14ddd7377 to your computer and use it in GitHub Desktop.
rppal async interrupt test (slightly modified from: https://users.rust-lang.org/t/good-gpio-crate-for-raspberry-pi-with-example-reading-code/104744/7)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::error::Error; | |
use std::io; | |
use rppal::gpio::{Gpio, Trigger}; // 0.16.1 | |
pub const BTN1: u8 = 13; | |
pub const BTN2: u8 = 4; | |
fn main() -> Result<(), Box<dyn Error>> { | |
let mut btns = [ | |
Gpio::new()?.get(BTN1)?.into_input_pullup(), | |
Gpio::new()?.get(BTN2)?.into_input_pullup(), | |
]; | |
for (i, btn) in btns.iter_mut().enumerate() { | |
btn.set_reset_on_drop(false); | |
btn.set_async_interrupt(Trigger::Both, move |lvl| eprintln!("btn {i} is now {lvl}"))?; | |
} | |
eprintln!("Play with the buttons, and hit Enter when done to terminate."); | |
let mut s = String::new(); | |
io::stdin().read_line(&mut s)?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment