#[cfg(not(feature = "async"))]
fn main() {
eprintln!("examples/continuous.rs requires --features async");
}
#[cfg(feature = "async")]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
use anyhow::anyhow;
use pico_de_gallo_hal::Hal;
use tmp108::Tmp108;
let hal = Hal::new();
let i2c = hal.i2c();
let mut delay = hal.delay();
let mut tmp = Tmp108::new_with_a0_gnd(i2c);
tmp.continuous(async |t| {
for _ in 0..5 {
let temperature = t.wait_for_temperature(&mut delay).await?;
println!("Temperature: {temperature:.2} C");
}
Ok(())
})
.await
.map_err(|_| anyhow!("Continuous conversion failed"))?;
Ok(())
}