user76576: I have 16x2 LCD display with a I2C backpack. This is the library I am using
https://drive.google.com/drive/folders/16_UqfwFm4VKWcdeJfDmHRV2Hj_IoaTai?usp=sharing
So as given in the code below, by changing variable back to a 0 or 1, I can turn on and off the backlight. However if I change the values of back to 100, or 50 the backlight does not get affected, how do I make this happen without the need of an external resistor/potentiometer and but with code.
Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off.
If you don't care of the above here's it summarized-
How do I control Backlight of LCD with I2C backpack through code?
Code-
#include "LiquidCrystal_PCF8574.h"
#define LCD_ADDRESS 0x27
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
int back = 1; // 1-on, 0-off

LiquidCrystal_PCF8574 lcdI2C;

void setup(){
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
}

void loop(){
delay(1000);
back = 0;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
delay(1000);
back = 1;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);

}


user4143: You don't.  The PCF8574 is an IO expander. It doesn't have any provision for PWM. It's either on, or off.

76576: <p>I have 16x2 LCD display with a I2C backpack. This is the library I am using
<a href="https://drive.google.com/drive/folders/16_UqfwFm4VKWcdeJfDmHRV2Hj_IoaTai?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/drive/folders/16_UqfwFm4VKWcdeJfDmHRV2Hj_IoaTai?usp=sharing</a></p>
<p>So as given in the code below, by changing variable <code>back</code> to a 0 or 1, I can turn on and off the backlight. However if I change the values of <code>back</code> to 100, or 50 the backlight does not get affected, how do I make this happen without the need of an external resistor/potentiometer and but with code.</p>
<p>Note that on my backpack, there is no connection between pins A and K to keep the backlight on but if I connect the two, then the backlight is turned off.</p>
<p>If you don't care of the above here's it summarized-</p>
<p><strong>How do I control Backlight of LCD with I2C backpack through code?</strong></p>
<p>Code-</p>
<pre><code>#include &quot;LiquidCrystal_PCF8574.h&quot;
#define LCD_ADDRESS 0x27
#define LCD_ROWS 2
#define LCD_COLUMNS 16
#define SCROLL_DELAY 150
int back = 1; // 1-on, 0-off

LiquidCrystal_PCF8574 lcdI2C;

void setup(){
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
}

void loop(){
delay(1000);
back = 0;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);
delay(1000);
back = 1;
lcdI2C.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, back);

}
</code></pre>
 4143: <p>You don't.  The PCF8574 is an IO expander. It doesn't have any provision for PWM. It's either on, or off.</p>
