diff options
Diffstat (limited to 'examples/rp/src/bin/adc.rs')
| -rw-r--r-- | examples/rp/src/bin/adc.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/examples/rp/src/bin/adc.rs b/examples/rp/src/bin/adc.rs index 65069cde1..81a8b8340 100644 --- a/examples/rp/src/bin/adc.rs +++ b/examples/rp/src/bin/adc.rs | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | //! This example test the ADC (Analog to Digital Conversion) of the RS2040 pin 26, 27 and 28. | ||
| 2 | //! It also reads the temperature sensor in the chip. | ||
| 3 | |||
| 1 | #![no_std] | 4 | #![no_std] |
| 2 | #![no_main] | 5 | #![no_main] |
| 3 | #![feature(type_alias_impl_trait)] | 6 | #![feature(type_alias_impl_trait)] |
| @@ -38,5 +41,8 @@ async fn main(_spawner: Spawner) { | |||
| 38 | 41 | ||
| 39 | fn convert_to_celsius(raw_temp: u16) -> f32 { | 42 | fn convert_to_celsius(raw_temp: u16) -> f32 { |
| 40 | // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet | 43 | // According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet |
| 41 | 27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 as f32 | 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 | ||
| 42 | } | 48 | } |
