File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
examples/SimpleTemperature Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,16 @@ void loop()
3232{
3333 if (IMU.temperatureAvailable ())
3434 {
35- int temperature_deg = 0 ;
36- IMU.readTemperature (temperature_deg);
35+ int temperature_int = 0 ;
36+ float temperature_float = 0 ;
37+ IMU.readTemperature (temperature_int);
38+ IMU.readTemperatureFloat (temperature_float);
3739
3840 Serial.print (" LSM6DSOX Temperature = " );
39- Serial.print (temperature_deg);
41+ Serial.print (temperature_int);
42+ Serial.print (" (" );
43+ Serial.print (temperature_float);
44+ Serial.print (" )" );
4045 Serial.println (" °C" );
4146 }
4247}
Original file line number Diff line number Diff line change @@ -174,7 +174,17 @@ int LSM6DSOXClass::gyroscopeAvailable()
174174 return 0 ;
175175}
176176
177- int LSM6DSOXClass::readTemperature (int & temperature_deg)
177+ int LSM6DSOXClass::readTemperature (int & temperature_deg)
178+ {
179+ float temperature_float = 0 ;
180+ readTemperatureFloat (temperature_float);
181+
182+ temperature_deg = static_cast <int >(temperature_float);
183+
184+ return 1 ;
185+ }
186+
187+ int LSM6DSOXClass::readTemperatureFloat (float & temperature_deg)
178188{
179189 /* Read the raw temperature from the sensor. */
180190 int16_t temperature_raw = 0 ;
@@ -187,7 +197,7 @@ int LSM6DSOXClass::readTemperature(int & temperature_deg)
187197 static int const TEMPERATURE_LSB_per_DEG = 256 ;
188198 static int const TEMPERATURE_OFFSET_DEG = 25 ;
189199
190- temperature_deg = (static_cast <int >(temperature_raw) / TEMPERATURE_LSB_per_DEG) + TEMPERATURE_OFFSET_DEG;
200+ temperature_deg = (static_cast <float >(temperature_raw) / TEMPERATURE_LSB_per_DEG) + TEMPERATURE_OFFSET_DEG;
191201
192202 return 1 ;
193203}
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ class LSM6DSOXClass {
4242 int gyroscopeAvailable (); // Check for available data from gyroscope
4343
4444 // Temperature
45- int readTemperature (int & temperature_deg);
45+ int readTemperature (int & temperature_deg);
46+ int readTemperatureFloat (float & temperature_deg);
4647 int temperatureAvailable ();
4748
4849 private:
You can’t perform that action at this time.
0 commit comments