i want only one decimal on a value.

Hi! =)

Have a problem that i cant get my head around..

I have a presure sensor and a display that shows me the value in Bar.
The lcd prints out my value like this...

0.05 bar

and thats al fine...

But what i can understand is if you have more decimals on a value you print the slower the system gets..

And i have about 6-8 values that i want to monitor on my lcd 4x20

The code is folowing...

int SensorPort = 0; // Set MAP sensor input on Analog port 0
double SensorValue = 0; //Save Sensor input Voltage
float kPa = 0; // Save Result in kPa
float Bar = 0; // Save Result in Bar

SensorValue = analogRead(SensorPort);
kPa = (SensorValue*(.00488)/(.022)+20);
Bar = (kPa * 0.01) - 1.0172; //multiply (1 kPa x 0.01 bar) and deduct atmospheric pressure
lcd2.setCursor (0,0);
lcd2.print (Bar);
lcd2.print (" Bar");
kPa = 0;
Bar = 0;
SensorValue = 0;

Is there eanyway i just can get one decimal after the comma like (1.2bars) i dont need (1.23 Bars)
Eany help is welcome.



You might save even more time by putting

lcd2.print (" Bar");

in the setup, rather than in the loop as youy apparently have at the moment.

multiply is faster than divide

kPa = (SensorValue*(.00488)/(.022)+20);
is a fixed value.

why not just

kPa = (SensorValue*20.22181818)

and you know that 0.1 to 0.49kpa = 0.0 bar, right ?
you probably don't need that many decimal places here as they will be discarded when converting to bar.

atmospheric pressure is not constant, but could be in your case if you are not concerned about changes in barometric pressure.

if you subtracted 0.1 kpa from your reading, you would be reducing your math even more.
I have not run the spreadsheet, but since you are only interested in bar, the decimals are going to be lost, so there would not be any need to do decimal math past 2 places in kPa.

can kPa be an int?
it may be since there are no decimals in kPa that will be in bar.

this is the result of the 10bit ADC input ?

double SensorValue = 0; //Save Sensor input Voltage

the only possible values are 0 to 1024, in whole numbers ?

also, does it have to be global ?
why to you zero kPa ?
kPa does not appear to need to be global