Hi I bought an LCD Display with an backlight and want to make the backlight go brighter as the light gets less but at this moment, the more light enters the LDR lhe more bright the display gets and visaversa :0
can somebody help?
You could use a subtract operator, or you could use "map".
Can you provide a link to the datasheet of the LCD?
How is the brightness controlled?
I'd guess that the LDR you have will give a higher reading when it is brighter, and a lower reading when it is darker. Therefore, all you need to do is
brightVal = 1023 - analogRead(sensorPin);
This takes a reading of the LDR, then subtracts that value from 1023 - the biggest number returned from analogRead. That way, the higher the input voltage, the lower the reading will be. Then, you can control the backlight.
How are you controlling the backlight? If it is from a PWM pin, you'll need to divide brightVal by four for it to work properly. Also, it is important that you do not connect the backlight straight to the pin, otherwise you will blow it (the pin).
Onions.
Or what you could do is:
Remap the values,
brightVal = map(0, 1023, 0, 255)
I don't see the inversion in that last response.
It might be a double inversion ![]()