#!/usr/bin/env cargo run
use jetsongpio::{Direction, Edge, GPIO, Level, Mode};
use std::thread;
use std::time::Duration;
const LED_PIN: u32 = 12; const BUTTON_PIN: u32 = 18;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let gpio = GPIO::new();
gpio.setmode(Mode::BOARD)?;
gpio.setup(vec![LED_PIN], Direction::OUT, Some(Level::LOW), None)?;
gpio.setup(vec![BUTTON_PIN], Direction::IN, None, None)?;
gpio.output(vec![LED_PIN], vec![Level::LOW])?;
println!("Starting demo now! Press CTRL+C to exit");
println!("Waiting for button event on pin {}", BUTTON_PIN);
loop {
if gpio
.wait_for_edge(BUTTON_PIN, Edge::Falling, None)?
.is_some()
{
println!("Button Pressed!");
gpio.output(vec![LED_PIN], vec![Level::HIGH])?;
thread::sleep(Duration::from_secs(1));
gpio.output(vec![LED_PIN], vec![Level::LOW])?;
}
}
}