for the uv sensor, i need to use a libary, which has a calculation included
can someone explain, what the float calculation do?
They use this calculating:
It "maps" values to a different range and offset in a linear way.
Suppose an analog channel has a value of 0...1023, and that indicates a pressure of 10...100.
So you get:
0 -> 10
1023 -> 100
Everything in between should be in a linear way.
The input range is 1023 (from 0 to 1023).
The output range is 90 (from 10 to 100).
The input offset is 0 and the output offset is 10.
The most important is the range. The 1023 should be mapped onto the 90. That is done by dividing with 1023 and multiplying with 90.
Add the offset and you get:
int value = analogRead(A0);
pressure = float(value) / 1023 * 90 + 10;
The range for the input is (in_max - in_min).
The offset for the input is in_min.
The range for the output is (out_max - out_min).
The offset for the output is out_min.
Put the division with the range in a function, add the input offset and output offset, and then you get that calculation.
Can you see the overall intention ? It is about the range. The offsets are solved before and after mapping the ranges onto each other.
Suppose that you have a voltage of 0...5V and you need to convert that to a speed of 2...-10 m/s.
That means you have to get rid of the unit "voltage". That is done by dividing with the voltage range (which is 5). After that there is a universal value of 0...1 that does not have a unit.
Then you have to introduce the unit "speed". That is done by multiplying with the speed range (which is -12).