I would like to have a little function that dims up the LCD backlight before diplaying info and then dims it down when no new information is needs to be displayed.
I don't see anything wrong with this code, however:
the backlight is less bright than if hooked up to the +5V rail
the screen blinks at the end of the fade to dark and before fading back to full light; and again when fully lit and before dimming to dark.
Here is a little video to illustrate the blinking situation
I suspect this has to do with the Atmega's internals but I'm not skilled enough to know more than that. Any advice on how to fix this? Or a better way to accomplish this dimming effect without the glitches and with full backlighting?
void fadeLCD(byte mode, int duration) {
if (mode == 1) {
for (brightness = 0; brightness <= 255; brightness++) {
analogWrite(backlightPin, brightness);
if (brightness != 255) {
delay(duration/256);
}
}
}
if (mode == 0) {
for (brightness = 255; brightness >= 0; brightness--) {
analogWrite(backlightPin, brightness);
if (brightness != 0) {
delay(duration/256);
}
}
}
}
However, I would like to use "up" and "down" for the value of mode, out of clarity. But if I do this:
void fadeLCD(byte mode, int duration) {
and call the function with
fadeLCD('up',fadeLen);
it doesn't work.
How can I do? Is it possible at all?
Also, I checked the voltage on the PWM and the +5V rail: they are identical (when the PWN reaches max value). Why would the backlight not be as bright as if I hooked it up straight to the +5V rail?
Do you notice the flicker pwm makes? I havent had the chance to try it but i think if you change the prescaler to a faster pwm there will be no flicker and who kbows maybe look brighter,
this line will make it faster, at the end 0x3 is normal, higher number is faster i believe up to like 6
TCCR2B = TCCR2B & B01111000 | 0x04;// SET PRESCALER
You can in such a case use a transistor with its base connected to the pwm pin with a 220min resistor, just like you drive a high power motor or relay,take care of the base current needed to turn the transistor on as chip can supply a max of 40ma.
Could you give more details please? I have a PN2222 transistor as part of my Arduino starters kit but I have never used it and I have no idea how to wire it up...
Could you give more details please? I have a PN2222 transistor as part of my Arduino starters kit but I have never used it and I have no idea how to wire it up...
Follow this:
But only use one LED. Or use multiple. Who am I to tell you what to do?
Also note that R2-R5 will depend on how much current your LED wants. Use this page