I am using this example on how to use a photoresistor to detect the value of light that the sensor is getting but I want to convert the reading of the resistor to a percentage but I can't use the map()
function from the Arduino docs but I can implement something similar to it
so I created this simple function
float photo_resistor(int pinNum)
{
float reading = analogRead(pinNum);
if (reading == 54)
{
return 0.0;
}
return (reading - 54)/(100/920);
}
as in the docs I want to use an output range from 0 to 100 and the minimum reading i got is 54 and the maximum is 974
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
// this becomes (x - 54)*(100 - 0 ) / ( 974 - 54) + 0;
// (x-54)/(100/920);
but this does not output a value from on the scale from 0-100