I am mesuring temperature via two sensors. To smooth things out, I am making a weighted average of the historical readings vs the new reading (the tempC function is to read the thermistor via the analog pins):
I have then written a function that is supposed to print an arrow on the LCD, depending on the trend:
void calcTrend(float prevAvg, float currAvg) {
if (currAvg > 1.05 * prevAvg) {
lcd.setCursor(19,1);
lcd.write(2); // trend is up
}
if (currAvg >= 1.05 * prevAvg && currAvg <= 0.95 * prevAvg) {
lcd.setCursor(19,1);
lcd.write(3); // trend is steady
}
if (currAvg < 0.95 * prevAvg) {
lcd.setCursor(19,1);
lcd.write(4); // trend is down
}
}
However, there is something wrong with the function.
I have put this ±5% margin because the readings are not steady, they change by a few 1/10th of a degree with every reading (even with the smoothing).
I'm getting very confused when it comes to intervals and I can't see what's wrong... Any suggestions?
It still doesn't work, and doesn't display any arrow at all.
I tried the arrows and they work, so it seems that the Arduino can't find any if() statement fitting the situation.
It feels great to be helpful!
It's easier for everyone when the person who needs help listens like you did.
I wish everyone was so capable of listening to suggestions...