diff --git a/advanced/i2c-sensor-reading/examples/part_1.rs b/advanced/i2c-sensor-reading/examples/part_1.rs index 4a3f7194..109464aa 100644 --- a/advanced/i2c-sensor-reading/examples/part_1.rs +++ b/advanced/i2c-sensor-reading/examples/part_1.rs @@ -32,17 +32,20 @@ fn main() -> Result<()> { let device_id = sht.device_identifier().unwrap(); println!("Device ID SHTC3: {:#02x}", device_id); + // 5. Start measurements + sht.start_measurement(PowerMode::NormalMode).unwrap(); + loop { - // 5. This loop initiates measurements, reads values and prints humidity in % and Temperature in °C. - sht.start_measurement(PowerMode::NormalMode).unwrap(); - FreeRtos.delay_ms(100u32); - let measurement = sht.get_measurement_result().unwrap(); - - println!( - "TEMP: {:.2} °C | HUM: {:.2} %", - measurement.temperature.as_degrees_celsius(), - measurement.humidity.as_percent(), - ); + // 6. This loop initiates measurements, reads values and prints humidity in % and Temperature in °C. + if let Ok(measurement) = sht.get_measurement_result() { + println!( + "TEMP: {:.2} °C | HUM: {:.2} %", + measurement.temperature.as_degrees_celsius(), + measurement.humidity.as_percent(), + ); + + sht.start_measurement(PowerMode::NormalMode).unwrap(); + } FreeRtos.delay_ms(500u32); }