map float 0-5v

I am trying to get a air fuel mixture to display the correct values on a lcd display.
The 0v value is 7.35
The 5v value is 22.39

With this code i get the values min of 7 and max of 22 but no decimal points

``````int lambda0 = 7.35;
int lambda5 = 22.39;

sensorValue = map(sensorValue, 0, 1023, lambda0, lambda5);
float lambdaAFR= sensorValue;
``````

With this code i get the values min of 0 and max of 22.39 but i have no clue how to make the 0v display 7.35 on the lcd

``````int lambda0 = 7.35;
int lambda5 = 22.39;

float lambdaAFR= sensorValue * (22.39 / 1023.0);
``````

So any help would be helpfull

``````int lambda0 = 7.35;
``````

Go to the reference section of this site. At the top of this page, Learning --> Reference. Look at the entry for int. Study a little on what types of numbers an int can and cannot hold (hint int is short for integer). Then look at some of the other entries and see if there is one more appropriate for the numbers you have.

I get a little what you mean, that i can not use int for that but even i use it like this it also gives me no decimal points only 7.00 and 22.00

``````int sensorValue = analogRead(A2);
sensorValue = map(sensorValue, 0, 1023, 7.35, 22.39);
float lambdaAFR= sensorValue;
``````

Again, sensorValue is defined as an int. The fact that you put that value into a float later does not change the fact that an int can't hold a decimal part.

Next you need to go back to the reference one more time and look at the entry for map. What variable type does it return? Will that variable type hold a decimal part? What variable types are its arguments? Will the numbers you use work with those?

i have done it now like this and it works

``````int sensorValue = analogRead(A2);
float lambdaAFR= (map(sensorValue,0, 1023, 735, 2239));
float lambdaAFR2 = lambdaAFR / 100;
``````

Get rid of the "Magic Numbers" and also map():

``````const float lambda_0V = 7.35;
const float lambda_5V = 22.39;

float lambda AFR = lambda_0V + ( (lambda_5V - lambda_0V) * analogRead(A2) / 1024);
``````

Thanks a lot that also works

What aarg wrote does work. But this has an issue. I guess you never took my advise to look up what type map returns.

``````float lambdaAFR= (map(sensorValue,0, 1023, 735, 2239));
``````

you have to consider that i am very new at this and already happy if i do something and it works.
i have looked at the reference pages but is do not fully understand it

gijsje:
you have to consider that i am very new at this and already happy if i do something and it works.
i have looked at the reference pages but is do not fully understand it

OK what part don't you understand? Do you see what type map returns? What type is that? Have you looked at the entry for that type? Will it hold decimal numbers?

There's nothing esoteric here to misunderstand for being new. All you really need to be able to do to get this one is to be able to read.

You do have to understand the difference between integers and floating point. That will get you in big trouble if you don't.

aarg:
Get rid of the "Magic Numbers" and also map():

``````const float lambda_0V = 7.35;
``````

const float lambda_5V = 22.39;

float lambda AFR = lambda_0V + ( (lambda_5V - lambda_0V) * analogRead(A2) / 1024);

Yes, map() is overused.