A personal rust firmware for the Badger 2040 W
at 8526e7942199459b583a797bf9849f211d18c1e4 37 lines 1.3 kB view raw
1use defmt::*; 2use embassy_rp::i2c::{I2c, SclPin, SdaPin}; 3use embassy_rp::peripherals::I2C0; 4use embassy_rp::{i2c, Peripheral}; 5use embassy_time::Timer; 6use shtcx::{self, PowerMode}; 7 8use crate::badge_display::{HUMIDITY, TEMP}; // Import the necessary items from shtcx 9 10#[embassy_executor::task] 11pub async fn run_the_temp_sensor( 12 i2c0: I2C0, 13 scl: impl Peripheral<P = impl SclPin<I2C0>> + 'static, 14 sda: impl Peripheral<P = impl SdaPin<I2C0>> + 'static, 15) { 16 let i2c = I2c::new_blocking(i2c0, scl, sda, i2c::Config::default()); 17 18 let mut sht = shtcx::shtc3(i2c); 19 let mut sht_delay = embassy_time::Delay; // Create a delay instance 20 21 loop { 22 let combined = sht.measure(PowerMode::NormalMode, &mut sht_delay).unwrap(); 23 let celsius = combined.temperature.as_degrees_celsius(); 24 let fahrenheit = (celsius * 9.0 / 5.0) + 32.0; 25 info!( 26 "Temperature: {}°F, Humidity: {}%", 27 fahrenheit, 28 combined.humidity.as_percent() 29 ); 30 TEMP.store(fahrenheit as u8, core::sync::atomic::Ordering::Relaxed); 31 HUMIDITY.store( 32 combined.humidity.as_percent() as u8, 33 core::sync::atomic::Ordering::Relaxed, 34 ); 35 Timer::after_secs(30).await; 36 } 37}