Rotating Elegoo Display from Portrait to Landscape

Hi Guys,

I am trying to create a GUI for a project i am working on, and have purchased a touchscreen to use with it. I have no idea how to code a touchscreen, and have been adjusting one of the examples that came with the screen. However, the example was in portrait, and i want it in landscape. I changed the line tft.setRotation(1), to 3, which changed the picture on the screen, however the touch part still thinks it is in portrait.
I think i have narrowed down the section of code relating to the touch, highlighted below, but cannot get it to work properly.
Can any of you help me please?

Thanks,
Chris

tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(BLACK);

// create buttons
for (uint8_t row=0; row<5; row++) {
for (uint8_t col=0; col<3; col++) {
buttons[col + row3].initButton(&tft, BUTTON_X+col(BUTTON_W+BUTTON_SPACING_X),
BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row3], ILI9341_WHITE,
buttonlabels[col + row
3], BUTTON_TEXTSIZE);
buttons[col + row*3].drawButton();
}
}

// create 'text field'
tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);

}
// Print something in the mini status bar with either flashstring
void status(const __FlashStringHelper *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
// or charstring
void status(char *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop(void) {
/*TSPoint p;
p = ts.getPoint();
*/
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);

// if sharing pins, you'll need to fix the directions of the touchscreen pins
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);

// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!

// p = ts.getPoint();
/*
if (ts.bufferSize()) {

} else {
// this is our way of tracking touch 'release'!
p.x = p.y = p.z = -1;
}*/

// Scale from ~0->4000 to tft.width using the calibration #'s
/*
if (p.z != -1) {
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
Serial.print("("); Serial.print(p.x); Serial.print(", ");
Serial.print(p.y); Serial.print(", ");
Serial.print(p.z); Serial.println(") ");
}*/
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = (tft.height()-map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
}

// go thru all the buttons, checking if they were pressed
for (uint8_t b=0; b<15; b++) {
if (buttons**.contains(p.x, p.y))[/color] {**
** //Serial.print("Pressing: "); Serial.println(b);**
__ buttons**.press(true); // tell the button it is pressed**__
** } else {**
__ buttons**.press(false); // tell the button it is NOT pressed**
** }
}
// now we can ask the buttons if their state has changed**
** for (uint8_t b=0; b<15; b++) {**
if (buttons**.justReleased()) {
// Serial.print("Released: "); Serial.println(b);
buttons.drawButton(); // draw normal**

** }**__

__ if (buttons**.justPressed()) {
buttons.drawButton(true); // draw invert!**__

** // if a numberpad button, append the relevant # to the textfield**
** if (b >= 3) {**
** if (textfield_i < TEXT_LEN) {
textfield[textfield_i] = buttonlabels[0];
textfield_i++;
textfield[textfield_i] = 0; // zero terminate**

but cannot get it to work properly.

When you push a button, the Arduino does the hokey-pokey, and you want it to do the macarena, instead?

What does the code ACTUALLY do, and how does that differ from what you want?

Thanks for your reply PaulS. I apologise for not being clear enough in my earlier post.

I am creating a set of automatic blinds, with varying modes. To change the modes of the blinds, i want to use a touchscreen, with a button for each mode.
I have created the buttons, and the appearance, and the example code has the code for registering the position of the input.
However, because i changed the screen from portrait to landscape, the positions now don't line up with the buttons.

Therefore, can anyone help me to change the mapping of the touch positions to landscape please.

Thanks

However, because i changed the screen from portrait to landscape, the positions now don't line up with the buttons.

Do the buttons appear where you expect them to?
When you touch the screen in the 4 corners, what coordinates are returned?

The buttons appear where i expect them to, and when they register a press, they go white to show this. However, when you press the image of the button, nothing happens, or another button goes white. For example, if i press the bottom right button, the bottom left button clicks, as this is where the button would be if the screen were vertical.

How about posting some real numbers. What is the coordinate when you press the upper, left corner? The upper, right corner? The lower, left, etc.

How do i find out the co-ordinates being registered? As i said, i am simply adapting the example code, and don't have any idea how to code a touchscreen.

Ok, i have managed to find out the co-ordinates the touchscreen is registering.
My screen is 320x240.
when i select the bottom right corner, the touchscreen reads (0, 240).
when i select the bottom left corner, the touchscreen reads (0, 0).
top left (320,0)
top right (320, 240).

Now, if only we knew the coordinates of the button corners, we could help you determine the relationship between the press location coordinate system (origin at the lower, left, X pointing to the right, Y pointing up) and the button definition coordinate system.

Snippets just do NOT cut it, here.