I have bought a 2.5" TFT shield online, which is equipped with the ILI9341 controller. I need to dim the intensity of the background LEDs to match ambient light.
This particular shield does not provide a pin to control the intensity of the LEDs with PWM via a separate input, so I need to dim the background LEDs of this display via software.
The zip file with the libraries can be downloaded here.
Does one of you know how can issue a command to the TFT display to dim the background LEDs?
Thanks in advance!
UPDATE 1:
I wrote a new function to set the display's brightness by controlling the background LEDs, but something is missing as I can seem to be writing correctly to the display. So I'm trying to get the display to answer to a known command first, like 0x28 (Display Off).
The new function is defined in Adafruit_TFTLCD.cpp:
// Set display brightness (background LED's)
void Adafruit_TFTLCD::setDisplayBrightness(uint8_t x) {
// Try with 0x28 (Display Off) to see if display reacts
writeRegister8(0x28, 0);
return;
}
The function prototype is defined in Adafruit_TFTLCD.h
// New functions
void setDisplayBrightness(uint8_t x);
Then I call the function in my main loop. To make sure, I first write some rectangles on screen, wait 5 seconds, then fill the screen with blue, call the new function and enter an endless loop so no other commands can interfere:
tft.fillScreen(BLUE);
tft.setDisplayBrightness(10); // Which really is command 0x28 to test
Any clues what I might be missing?
Thanks!
UPDATE 2:
I got so far as to have the ILI9341 react to some commands, but not all the time, and not to all commands. I suspect there is something in the way you issue the commands that I'm missing( timing?, sequence?, other?)
Here is what I have found out so far:
I can get the display to react to the Display Off command (0x28), but only when I issue it in the begin(..) function. So, the original code in Adafruit_TFTLCD.cpp is like this:
void Adafruit_TFTLCD::begin(uint16_t id) {
...
writeRegister8(ILI9341_DISPLAYON, 0);
delay(500);
If I change it to the following the display reacts by remaining white:
void Adafruit_TFTLCD::begin(uint16_t id) {
...
writeRegister8(ILI9341_DISPLAYON, 0);
writeRegister8(ILI9341_DISPLAYOFF, 0); // Display off is declared as 0x28
delay(500);
So, I have a reaction to command 28h.
Then I tried function 0x51 like this in the begin(...) function:
void Adafruit_TFTLCD::begin(uint16_t id) {
...
writeRegister8(ILI9341_DISPLAYON, 0);
delay(500);
writeRegister8(0x51, 0x80); // Test command 0x51 - background intensity
delay(500);
To no effect :-(
I even added command 0xBE (background PWM frequency) to see if it had any effect, but nothing :-(
void Adafruit_TFTLCD::begin(uint16_t id) {
...
writeRegister8(ILI9341_DISPLAYON, 0);
writeRegister8(0xbe, 0x80);
delay(500);
writeRegister8(0x51, 0x0);
delay(500);
Also if I issue the 0x28 command:
writeRegister8(ILI9341_DISPLAYOFF, 0)
elsewhere in Adafruit_TFTLCD (e.g. in FillScreen, Fill Rect etc, it doesn't work either).
Any ideas? They would be highly appreciated!