[SOLVED] Temperature in Whole Number

Solution: See this reply

Good Morning -
I am using this sample code and it works awesome. Is there an easy to make the temperature a whole number? I don’t care if the temp goes from 71.123 to 71.124, but more if it goes from 71 to 72. Any pointers?

SYSTEM_THREAD(ENABLED); // Makes the code run in threaded mode

// Add the temperature sensor library
#include "SI7020-A20_CE/SI7020-A20_CE.h"

// Create a temperature sensor object
SI7020_A20_CE tempSensor;

// Declare a variable to store temperature readings in
double tempF = 0;

// setup() only runs once, when the device is first powered on
void setup() {
    // Nothing needed in setup for this example!
}

// loop() runs again and again as fast as it can
void loop() {

    // Read the temperature sensor!
    tempF = tempSensor.temperatureF();

    // Publish that data to the cloud!
    Particle.publish("temperature", String(tempF), 60, PRIVATE);

    // Delay for 5000 milliseconds (aka 5 seconds)
    delay(5000);
}

something like this:

tempF = tempSensor.temperatureF();

int wholeNumberTemperature = floor(tempF + .5);

Particle.publish("temperature", String(wholeNumberTemperature), 60, PRIVATE);

I cannot recall if you need to:

#include "math.h"
4 Likes

Thanks @BulldogLowell! That worked well. :smile:

2 Likes