@@ -12,15 +12,14 @@ const C_TO_K_CONVERSION: f32 = 273.15;
12
12
// connected to a thermistor, with the ADS1015 is measuring the node connecting
13
13
// the two (a voltage divider circuit).
14
14
15
- const DIVIDER_RESISTANCE : f32 = 22000 .0; // Ohms
15
+ const DIVIDER_RESISTANCE : f32 = 1000 .0; // Ohms
16
16
const V_IN : f32 = 5.0 ; // Volts
17
17
const BETA : f32 = 3950.0 ; // Kelvins
18
18
const R_0 : f32 = 10000.0 ; // Ohms
19
19
const ROOM_TEMP : f32 = 25.0 + C_TO_K_CONVERSION ; // Kelvins
20
20
21
- fn voltage_to_temp ( voltage : i16 ) -> f32 {
22
- let voltage = f32:: from ( voltage) / 1000.0 ;
23
- let thermistor_resistance = ( voltage * DIVIDER_RESISTANCE ) / ( V_IN - voltage) ;
21
+ fn voltage_to_temp ( voltage : f32 ) -> f32 {
22
+ let thermistor_resistance = ( ( V_IN - voltage) * DIVIDER_RESISTANCE ) / voltage;
24
23
let r_inf = R_0 * std:: f32:: consts:: E . powf ( -BETA / ROOM_TEMP ) ;
25
24
let temp_kelvins = BETA / ( thermistor_resistance / r_inf) . ln ( ) ;
26
25
temp_kelvins - C_TO_K_CONVERSION
@@ -43,7 +42,7 @@ impl LimTemperature {
43
42
44
43
pub fn read_lim_temps ( & mut self ) -> [ f32 ; 4 ] {
45
44
[ SingleA0 , SingleA1 , SingleA2 , SingleA3 ]
46
- . map ( |channel| block ! ( self . ads1015. read( channel) ) . unwrap ( ) )
45
+ . map ( |channel| f32 :: from ( block ! ( self . ads1015. read( channel) ) . unwrap ( ) ) / 1000.0 )
47
46
. map ( voltage_to_temp)
48
47
}
49
48
}
0 commit comments