summaryrefslogtreecommitdiffstats
path: root/src/bin/btn-test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/btn-test.rs')
-rw-r--r--src/bin/btn-test.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/bin/btn-test.rs b/src/bin/btn-test.rs
new file mode 100644
index 0000000..b33e402
--- /dev/null
+++ b/src/bin/btn-test.rs
@@ -0,0 +1,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::Up);
+
+ // 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();
+ }
+ }
+}