button_control/
button_control.rs

1use ws_oled_driver::Device;  /* HAT Device */
2use ws_oled_driver::button::State;
3use anyhow::Result;
4
5fn main() -> Result<()> {
6  let mut device = Device::new()?;
7  device.initialize_components()?;
8
9  loop {
10    if let Some(button_state) = device.button_controller.read() {
11      match button_state {
12        State::Key1 => println!("Key1 pressed"),
13        State::Key2 => println!("Key2 pressed"),
14        State::Key3 => println!("Key3 pressed"),
15      }
16    }
17    else {
18      println!("Nothing Pressed!")
19    }
20  }
21}