Comparing a sensor measurement with the previous measurement

Hello,

I have been learning how to programme my Mega 2560 and I would like to learn how to compare a measurement with a previous measurement, say temperature for example. If the temperature has increased I would like to turn on a red LED if it has decreased, turn on a green LED or if the same, turn on both LED's. I have already set up a circuit with a DS18B20 temperature sensor and have tried some code that successfully reads the measured temperature and displays the temperature in the serial monitor.

Some help on how to compare a measurement to the previous measurement would be much appreciated.

Many thanks

When you've finished processing the current reading, store it in a 'last reading' variable. Next time round loop(), compare the new current reading with the stored 'last reading' and process accordingly.

Many thanks, I'll give it a go...

Thanks again dxw00d.

I modified the IfStatementCondition example code in the IDE. As I turn the potentiometer up, the led is on, as it is turned down, the led is off and is off if nothing changes.

Cheers