简体   繁体   中英

How do I dim the backlight on an 20x4 LCD Display with the i2c connected on an arduino uno

How to dim the backlight on an 20x4 LCD Display with the i2c connected to an Arduino uno?

I use the LiquidCrystal_I2C.h library and I can turn on and of the light with lcd.backlight(); and lcd.noBacklight();

But I don't want to turn off completely the backlight: I want to dim it.

Simple answer : You can't.

Complex Answer : You can use a BJT controlled by PWM to change/adapt the brightness.

Maybe a bit late, but I'd like to note that it is certainly possible to dim the backlight on LCDs that come with an I2C adaptor. It's as simple as wiring the upper pin (the one labeled LED) of the I2C board to a PWM pin in the Arduino. Using analogWrite() will vary the LED brightness from 0 (LED off) to 255.

Here's a simple sketch (for a 16 x 2 LCD) to demonstrate this:

#include <LiquidCrystal_I2C.h>

#define BRIGHTNESS_PIN      6   // Must be a PWM pin

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

byte brightness = 0;
bool sense = 1;

void setup()
{
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("Here's some text");
}

void loop()
{
    analogWrite(BRIGHTNESS_PIN, brightness);
    delay(10);

    if(sense) {
        if(brightness < 255) {
            brightness++;
        } else {
            sense = 0;
        }
    } else {
        if(brightness > 0) {
            brightness--;
        } else {
            sense = 1;
        }
    }
}

U can play around with lcd.backlight(); and lcd.noBacklight();

example

lcd.backlight(); delay(1); lcd.noBacklight(); delay(1);

It dims!

Most LCDs have 2 metal prongs on the side connected with a little black thing. This is the power to the backlight. If you pull the black thing out and place a resistor or potentiometer between the metal prongs (electrically not physically), it will dim the backlight. The other place you could put a resistor or pot is in the wires that are exposed to travel from the PCB to the backlight.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM