aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHenrik Berg <[email protected]>2023-07-13 22:47:03 +0200
committerHenrik Berg <[email protected]>2023-07-13 22:47:03 +0200
commit56ca1794759a21d9d5397e5bd4aa8226f6ef9385 (patch)
tree3d55df7b8d9b2443c442e7e2b7fad91494cd6b28 /examples
parent588c0479f5dacd21e8654463eb3ca3d847d5dcd9 (diff)
Round temp to make more sense.
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/adc.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs
index c0cbe0172..81a8b8340 100644
--- a/examples/rp/src/bin/adc.rs
+++ b/examples/rp/src/bin/adc.rs
@@ -41,5 +41,8 @@ async fn main(_spawner: Spawner) {
41 41
42fn convert_to_celsius(raw_temp: u16) -> f32 { 42fn convert_to_celsius(raw_temp: u16) -> f32 {
43 // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet 43 // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet
44 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 44 let temp = 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721;
45 let sign = if temp < 0.0 { -1.0 } else { 1.0 };
46 let rounded_temp_x10: i16 = ((temp * 10.0) + 0.5 * sign) as i16;
47 (rounded_temp_x10 as f32) / 10.0
45} 48}