Skip to content

Commit

Permalink
if let 構文を採用してみた
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshitakaNaraoka committed Feb 23, 2025
1 parent 202b2d4 commit 61eb408
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ use log::*; // log levelを使う為に必要
use std::time::Duration;
use std::thread;

// let on = State::On = pin.is_low();
// let off = State::Off = pin.is_high();

fn main() -> bool {
EspLogger::initialize_default(); // ロギングの初期化

let peripherals = Peripherals::take().unwrap();
let pin = PinDriver::input(peripherals.pins.gpio35)?;

let mut last_state = off; // 初期状態を保存
let mut last_state = pin.is_high(); // 初期状態を保存
let debounce_delay = Duration::from_millis(50); // チャタリング対策の遅延

loop {
let current_state = pin.is_high(); // 現在の状態を取得
match {
pin.is_low() => info!("HelloButton!"),
pin.is_high() => thread::sleep(Duration::from_millis(10)),
}
let current_state = pin.is_low(); // 現在の状態を取得
if let last_state = current_state {
info!("HelloButton!")
}
thread::sleep(Duration::from_millis(10)); // 状態確認の間隔
}
/*
if current_state != last_state {
Expand All @@ -39,5 +36,4 @@ fn main() -> bool {
}
thread::sleep(Duration::from_millis(10)); // 状態確認の間隔
*/
}
}

0 comments on commit 61eb408

Please sign in to comment.