summaryrefslogtreecommitdiffstats
path: root/src/bin/btn-test.rs
blob: 87663ef3bfcc7e9f57428d7040cae6d8a04b2956 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{
  gpio::{Input, Level, Output, Pull},
  main,
};
use esp_println::println;

#[main]
fn main() -> ! {
  let peripherals = esp_hal::init(esp_hal::Config::default());

  println!("Hello world!");

  // Set GPIO7 as an output, and set its state high initially.
  let mut led = Output::new(peripherals.GPIO1, Level::Low);
  let button = Input::new(peripherals.GPIO3, Pull::Down);

  // Check the button state and set the LED state accordingly.
  loop {
    if button.is_high() {
      println!("high");
      led.set_high();
    } else {
      println!("low");
      led.set_low();
    }
  }
}