use std::error::Error;
use std::thread;
use std::time::Duration;

use rppal::gpio::Gpio;
use rppal::gpio::Level;

const GPIO_LED: u8 = 23;
const GPIO_SW: u8 = 22;

fn main() -> Result<(), Box<dyn Error>> {
    let mut led = Gpio::new()?.get(GPIO_LED)?.into_output();
    let sw = Gpio::new()?.get(GPIO_SW)?.into_input();

    loop {
        if sw.read() == Level::High {
            led.set_high();
        }
        thread::sleep(Duration::from_millis(500));

        led.set_low();
        thread::sleep(Duration::from_millis(500));
    }
}
