redValue = redSensorValue/4
We divide by 4 to convert from 0-1023 to 0-255. Then we use this value to analogWrite to redLEDPin:
analogWrite(redLEDPin, redValue);
The greater the number of the divider, the lesser the value will be. Thus if I divide by 40 instead of 4 I will get lesser values in the Serial Monitor. Since the value is used as an output in analogWrite, shouldn't the red LED glow lighter if I divided by a large number?
What I see in my project is that the red LED glows brighter when I divide the redSensorValue by a large number.
Can anyone please explain this?
Strange as it may sound, the voltage is not changing.
These pins are using PWM ( Pulse width modulation). This means that the switch is on for a short part of time and then off for part of the time.
Sort of like ------------ . The on lines should be solid like the off lines and they are connected into one line.
The longer the voltage is high, the brighter the light will appear to be. Actually, things are happening so fast that we cannot see them.
That sort of explains what is happening.
Now then, the book says something about our eyes perceiving the brightness. It says we have problems seeing the difference as the light gets brighter.
I hope this sort of explains it enough.
Ken