Answer the question
In order to leave comments, you need to log in
How to round the received value from the analog input to tenths?
How to round the received value from the analog input to tenths?
The value is displayed on the LCD display, the value must be displayed in tenths.
#include <LiquidCrystal.h>
#include <math.h>
#define analogPin A0
#define beta 4090
LiquidCrystal lcd(3,4,8,9,10,11);
double termo = 0;
float voltage;
int temp;
void setup()
{
lcd.begin(16,2);
lcd.print("Temperature:");
lcd.setCursor(6,1);
lcd.print("C");
}
void loop()
{
long a = analogRead(analogPin);
// расчет по формуле
float termo = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
delay(100);
lcd.setCursor(0,1);
lcd.print(termo);
}
Answer the question
In order to leave comments, you need to log in
char str_temp[6];
/* 4 is mininum width, 1 is precision; float value is copied onto str_temp*/
dtostrf(termo , 4, 1, str_temp);
sprintf(temperature,"%s F", str_temp);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question