Skip to content

Commit af36c90

Browse files
Update examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino
Co-Authored-By: per1234 <[email protected]> Update src/MKRTHERM.cpp Co-Authored-By: per1234 <[email protected]> Update examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino Co-Authored-By: per1234 <[email protected]> Update examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino Co-Authored-By: per1234 <[email protected]> Made the function default to celcius as suggested.
1 parent d0a40c1 commit af36c90

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
MKR THERM Shield - Read Sensors
33
4-
This example reads the temperatures (in fahrenheit and kelvin) measured by the thermocouple
4+
This example reads the temperatures (in Fahrenheit and kelvins) measured by the thermocouple
55
connected to the MKR THERM shield and prints them to the Serial Monitor
66
once a second.
77
@@ -33,13 +33,13 @@ void loop() {
3333
Serial.print(THERM.readReferenceTemperature());
3434
Serial.println(" °C");
3535

36-
Serial.print("Temperature in Fahrenheit");
36+
Serial.print("Temperature in Fahrenheit ");
3737
Serial.print(THERM.readTemperature(FAHRENHEIT));
3838
Serial.println(" °F");
3939

40-
Serial.print("Temperature in Kelvin");
40+
Serial.print("Temperature in Kelvin ");
4141
Serial.print(THERM.readTemperature(KELVIN));
42-
Serial.println(" °F");
42+
Serial.println(" K");
4343

4444
Serial.println();
4545

src/MKRTHERM.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,12 @@ float THERMClass::readTemperature(int units)
9696
// multiply for the LSB value
9797
celsius = rawword * 0.25f;
9898

99-
if(units=FAHRENHEIT)
100-
{
101-
return (celsius * 9.0 / 5.0) + 32.0;
102-
}
103-
else if(units=KELVIN)
104-
{
105-
return (celsius + 273.15);
106-
}
107-
else if(units=CELSIUS)
108-
{
109-
return celsius;
99+
if (units == FAHRENHEIT) {
100+
return (celsius * 9.0 / 5.0) + 32.0;
101+
} else if(units == KELVIN) {
102+
return (celsius + 273.15);
103+
} else {
104+
return celsius;
110105
}
111106
}
112107

0 commit comments

Comments
 (0)