1. Francisco Malpartida
  2. New LiquidCrystal
  3. Issues


Issue #27 new

Consider Ardino pin control of backlight

Bill Perry
created an issue

Currently the function setBacklightPin() is used to set the bit within the output latch on the communication interface. i.e. in the I2C code it is a bit that is used on the other side of the i2c interface and in the SR3W code it is a bit on the SR output latch. (SR and SR2W don't support this function) But the potential issue is that some boards, like the I2C extra I/O LCD board don't support controlling the backlight through the interface, they require using an additional Arduino pin. The library "as is" has no support for this mode of operation, so users are left to having to use Arduino core functions like digitalWrite()/AnalogWrite() to control the backlight rather than being able to use the library functions like backlight(),noBacklight() and setBacklight().

What might be nice would be if the code supported using both modes of operation. i.e. it could use an output pin within the existing interface or assign an Arduino pin that works outside the interface.

In the glcd library I use some argument overloading (hidden from c++) to handle a few complex arguments. While it does side step the normal C++ typechecking, it is easy to do and this library could do the same. It uses a macro to alter the parameter in a way that it can be distinguished. So for example, it would be possible to do something like:


This would allow the constructor or other functions to be able to tell if the argument is a bit on the output latch or an actual Arduino pin. The glcd library version of this type of macro simply negates the value by inserting a minus sign. This allows to code to quickly and easily detect which type of argument is desired.\ In this example it would be:

define LCD_ARDUINO_PIN(pin) (-pin)

The code receiving the argument can simply look if the argument is negative to tell if it indicates and Arduino pin vs an interface output latch bit.

Some of the needed support for this would move up to the LCD common code and then depending on the type of backlight "pin" control selected, it would either handle itself , in the case of an arduino pin, or call the device layers backlight functions.

It is all doable and not very much code, and while it would allow the existing I2c Extra I/o board to have backlight control, I haven't seen any other boards out there that use a latching interface to the LCD and then use a separate Arduino pin for backlight control so it may not be worth the effort to add this support.

Comments (1)

  1. Alex Mitchell

    As well as the effort involved, I would be worried that this is essentially moving generic Arduino functionality (i.e. setting a pin high/low) into the LCD library. Yes, the pin is connected to an LCD, but it could equally be connected to anything else and making a digital write to a pin isn't specifically related to running an LCD. The module doesn't have the functionality to set the backlight, so that's a limitation of the hardware and in my opinion, we shouldn't try to work round this in library code. Instead, I would say that client code should have to handle it.

  2. Log in to comment