Blue/Red swapped on XC4630 TFT LCD

Does anyone know the fix for having red (0xF800) being displayed as blue, and blue (0x001FF) being displayed as red. This wouldn't be so much of a problem for solid red or blue in that I can just switch the red/blue hex values. But when displaying mix colours such as yellow, it comes out cyan.

I did some googling and came across this https://cal-eng.com/?page_id=981 but cannot find the mentioned code line anywhere in the Adafruit_GFX.cpp library file.

Using the Duinotech TFT shield with a genuine Uno.

Does anyone know a fix please?

The JayTech shield has a UC8230 controller.

Install MCUFRIEND_kbv and Adafruit_GFX libraries via the IDE Library Manager.

The UC8230 is relatively uncommon controller chip. So it is not enabled by default.

Edit the MCUFRIEND_kbv.cpp file to enable SUPPORT_8230 e.g. with Notepad
change this line:

//#define SUPPORT_8230              //UC8230 +118 bytes

to

#define SUPPORT_8230              //UC8230 +118 bytes

I have never actually seen a UC8230 screen but as fas I know, MCUFRIEND_kbv is the only library that supports this controller.

Please let me know if you have a problem.

David.

The mcufriend library works, and the colours are right. Was kinda hoping to just use the Adafruit ones as I can sorta understand how to implement more than one button. Haven't found any tutorials on how to do multiple buttons simply using the mcufriend library.

I only provide the Button_simple example with the library.

I have posted other sketches to the Forum. e.g. button demo
and button multiple

Note that all libraries that inherit Adafruit_GFX can do everything that Adafruit_GFX does.
e.g. Buttons, Bitmaps, FreeFonts, ...

David.

Oh sweet, just downloaded your button multiple code, runs perfectly. Will figure out how to mod it for my needs.
Problem is I don't fundamentally understand what is needed from scratch, but can figure out whats going on with code thats working and modify to suit.

Cheers

I strongly recommend printing the sketch on paper.

Study it with a nice cup of tea.

Scribble arrows and notes with a pencil directly on the paper.

I would appreciate feedback. Suggestions on how to document, improve, clarify.

David.

Paper and bourbon it is.

Would be awesome if you did a video that goes through using your multiple buttons code from setup to implementation (copying and pasting your code and trying it out on our own Arduinos as we follow video).
Maybe could do it on making a basic menu structure of like 6 buttons, and making each do something simple like switching digital pin on and off.

Too much to ask for free? :grinning: :grinning: :grinning:

Bourbon biscuits are ok but I prefer MacVities Digestive or Simmers Abernethy.

I am no good with camera or video.

I suppose that we could collaborate via GitHub. e.g. you create video, I add text.

To be honest, videos are fine for demonstrating capabilities but a demo sketch will do the same but in real life on your desk.

Regarding program structure. A real-life textbook, paper and pencils are probably the most effective.
Any video that I have seen is either too quick or too slow or too simple.

Or just studying existing code. Pick up tips for style, structure, flow, techniques, ...

David.

Damn I love McVitties. Can't beat a Tim Tam tho or a VoVo.

Well, I played with your code and got a demo working that I can use. Just has one menu which simply outputs to serial what button is pressed. I can work with this.

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x8230
const int TS_LEFT=908,TS_RT=106,TS_TOP=70,TS_BOT=888;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        // most apps use Portrait or Landscape. No need for all 4 cases
        switch (tft.getRotation()) {
            case 0:
                pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width());
                pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
                break;
            case 1:
                pixel_x = map(p.y, TS_TOP, TS_BOT, 0, tft.width());
                pixel_y = map(p.x, TS_RT, TS_LEFT, 0, tft.height());
                break;
            case 2:
                pixel_x = map(p.x, TS_RT, TS_LEFT, 0, tft.width());
                pixel_y = map(p.y, TS_BOT, TS_TOP, 0, tft.height());
                break;
            case 3:
                pixel_x = map(p.y, TS_BOT, TS_TOP, 0, tft.width());
                pixel_y = map(p.y, TS_LEFT, TS_RT, 0, tft.height());
                break;
        }
    }
    return pressed;
}

Adafruit_GFX_Button test1_btn, test2_btn, test3_btn, test4_btn, test5_btn;
// easier to handle a list of button pointers
Adafruit_GFX_Button *screen0[] = {&test1_btn, &test2_btn, &test3_btn, &test4_btn, &test5_btn, NULL };

int flag = 0, screen = 0;

// INITIALISE GPIO, TOUCH, TFT, BUTTONS
void setup(void)
{  Serial.begin(9600);
    tft.begin(tft.readID());
    tft.setRotation(0);     //PORTRAIT
test1_btn.initButton(&tft, 120,  20, 240, 40, TFT_WHITE, TFT_CYAN, TFT_BLACK, "Test1", 1);
test2_btn.initButton(&tft, 120,  64, 240, 40, TFT_WHITE, TFT_CYAN, TFT_BLACK, "Test2", 1);
test3_btn.initButton(&tft, 120, 108, 240, 40, TFT_WHITE, TFT_CYAN, TFT_BLACK, "Test3", 1);
test4_btn.initButton(&tft, 120, 152, 240, 40, TFT_WHITE, TFT_CYAN, TFT_BLACK, "Test4", 1);
test5_btn.initButton(&tft, 120, 196, 240, 40, TFT_WHITE, TFT_CYAN, TFT_BLACK, "Test5", 1);
    tft.fillScreen(TFT_BLACK);
      test1_btn.drawButton(false);
      test2_btn.drawButton(false);
      test3_btn.drawButton(false);
      test4_btn.drawButton(false);
      test5_btn.drawButton(false);
}

void loop(void)
{
    static uint16_t color = TFT_BLACK;
    // READ TOUCH
    if (screen == 0) {
        update_button_list(screen0);  //process all buttons
        if (test1_btn.justPressed()) {
          Serial.println("Test button 1 pressed");
        }
        if (test2_btn.justPressed()) {
          Serial.println("Test button 2 pressed");
        }
        if (test3_btn.justPressed()) {
          Serial.println("Test button 3 pressed");
        }
        if (test4_btn.justPressed()) {
          Serial.println("Test button 4 pressed");
        }
        if (test5_btn.justPressed()) {
          Serial.println("Test button 5 pressed");
        }                        
    }
}
    


/* update the state of a button and redraw as reqd
 *
 * main program can use isPressed(), justPressed() etc
 */
bool update_button(Adafruit_GFX_Button *b, bool down)
{
    b->press(down && b->contains(pixel_x, pixel_y));
    if (b->justReleased())
        b->drawButton(false);
    if (b->justPressed())
        b->drawButton(true);
    return down;
}

/* most screens have different sets of buttons
 * life is easier if you process whole list in one go
 */
bool update_button_list(Adafruit_GFX_Button **pb)
{
    bool down = Touch_getXY();
    for (int i = 0 ; pb[i] != NULL; i++) {
        update_button(pb[i], down);
    }
    return down;
}

void draw_button_list(Adafruit_GFX_Button **pb)
{
    tft.fillScreen(TFT_BLACK);
    for (int i = 0 ; pb[i] != NULL; i++) {
        pb[i]->drawButton(false);
    }
}