Skip to content

Instantly share code, notes, and snippets.

@manio
Created September 11, 2024 08:21
Show Gist options
  • Save manio/b612d5a16d3acd7a17eccda14ddd7377 to your computer and use it in GitHub Desktop.
Save manio/b612d5a16d3acd7a17eccda14ddd7377 to your computer and use it in GitHub Desktop.
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