All colors are blue

Hello,
I am using a ili9341 2.4' TFT LCD display with the TFTv2 library. I want to be able to change the color of the text but no matter what color I choose it displays the text in blue.
Here is the simplified code:

#include <TFTv2.h>
#include <SPI.h>
byte color;
void setup() {
  TFT_BL_ON;      
  Tft.TFTinit(); 
}
void loop() {
  color = '0xf800';
  Tft.drawString("Hello world!",0,0,2,color);
}

If I write the color name (RED) in Tft.drawString it displays the correct color but then I can't change it. Instead of byte I tried char and int and the result is the same. The shade is a bit different.

I do not know what I am doing wrong. Any help would be appreciated.

Are you uploading the new sketch after compiling?

If you are seeing blue... you should be seeing red here. : )

In your example, RED is defined in "565" (5 bits red, 6 bits green, 5 bits blue [(1111 1)(000 000)(0 0000] in the library file below... and any color in "565" found on the internet should work.

Hello,

Yes, I am uploading the sketch. The only way to see red is to write RED in the Tft.drawString line. tried writing 0xf800 and changing the color variable to byte, int, char. The result is blue text.

Use 'int' not 'byte`.

Do not use quotes (I missed that the first few times I looked, sorry).

1 Like

Got it working. Without quotes nothing is displayed when using byte for the variable. I switched from byte to int and now it's working. Thank you!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.