Where is that example/sample code from?
(I'd really like to get it updated)
While setBacklight() works for this device, I would discourage it's use to turn on/off the backlight
as it is used to set an intensity not just for on/off control.
On devices such as this that do not support backlight
dimming, any non zero value will turn the backlight full on, but on devices that support
dimming like when 4bit mode is used, setting the backlight intensity to 1 will be very dim.
If backlight on/off control is desired, then backlight() noBacklight() calls would be the
preferred method as those will work on any device that has backlight control and will
result in full on or full off.
fm's latest library allows setting the backlight bit and polarity in the constructor
as well as turns on the backlight in begin() for all device interfaces.
This can simplify the setup code in the sketch so that it can be the same regardless of the interface
(i2c, SR, 4bit, etc...)
All you have to do is setup the full constructor, then, the begin()
handles everything else regardless of the underlying interface to the LCD.
This allows the actual setup() sketch code to be consistent and the same for all interfaces.
i.e. if you change from i2c to 4bit, all that changes is the constructor.
The sketch code does not have to change.
So for example:
/*-----( Declare Constants )-----*/
#define I2C_ADDR 0x20 // Define I2C Address for the PCF8574T
//---(Following are the PCF8574 pin assignments to LCD connections )----
// This are different than earlier/different I2C LCD displays
#define BACKLIGHT_PIN 3
#define BACKLIGHT_POL POSITIVE // POSITIVE or NEGATIVE depending board design
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin, BACKLIGHT_PIN, BACKLIGHT_POL);
void setup() /*----( SETUP: RUNS ONCE )----*/
lcd.begin (20,4); // initialize the lcd, also turns on backlight
}// END Setup