TFT help

I need to have this sketch displayed as a landscape not a portrait. I tried to do this and it worked halfway. The picture went sideways but the touchscreen stayed as if it was still a portrait. If anyone has an answer please help.

#if 1

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

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;

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

Adafruit_GFX_Button on_btn, off_btn;

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);
  digitalWrite(YP, HIGH);   //because TFT control pins
  digitalWrite(XM, HIGH);
  bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
  if (pressed) {
      pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
      pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
  }
  return pressed;
}

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void)
{
  Serial.begin(9600);
  uint16_t ID = tft.readID();
  Serial.print("TFT ID = 0x");
  Serial.println(ID, HEX);
  Serial.println("Calibrate for your Touch Panel");
  if (ID == 0xD3D3) ID = 0x9486; // write-only shield
  tft.begin(ID);
  tft.setRotation(0);            //PORTRAIT
  tft.fillScreen(BLACK);
  on_btn.initButton(&tft,  60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
  off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
  on_btn.drawButton(false);
  off_btn.drawButton(false);
  tft.fillRect(40, 80, 160, 80, RED);
}

/* two buttons are quite simple
*/
void loop(void)
{
  bool down = Touch_getXY();
  on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
  off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
  if (on_btn.justReleased())
      on_btn.drawButton();
  if (off_btn.justReleased())
      off_btn.drawButton();
  if (on_btn.justPressed()) {
      on_btn.drawButton(true);
      tft.fillRect(40, 80, 160, 80, GREEN);
  }
  if (off_btn.justPressed()) {
      off_btn.drawButton(true);
      tft.fillRect(40, 80, 160, 80, RED);
  }
}
#endif

Please read these two posts:

General Guidance and How to use the Forum
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing or review.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

I fixed it but do you have an answer to the problem

jak234:
I fixed it but do you have an answer to the problem

No, but the chances of someone else helping you with this, are now greatly improved.

Ok I will make sure to do that next time I have a question.

Have you researched the Adafruit GFX API? It's very flexible, to accommodate the greatest number of possible displays. In fact, the low level code is quite complicated, in order to make that possible. I do remember that there is a setting for display orientation. The documentation is really quite good, too, so I would recommend having a good look there.

This was helpful to me it showed me how to rotate the picture that I am displaying. The issue is that the touch screen does not rotate with it. The buttons only work if Ipress where they would be if the display was in portrait mode.

Maybe try rotating the point returned from the getPoint() function (by +90 or -90 degrees depending on how you rotate the screen from portrait to landscape) into the coordinate system for landscape orientation.

How would I do that.

If you had read the Adafruit tutorial, you would have seen, in the red box with the exclamation mark, that...

Remember, if you rotate the screen drawing with setRotation() you'll have to use map() or similar to flip around the X/Y coordinates for the touchscreen as well! It doesn't know about drawing rotation

I wouldn't bother with map(). It's a simple transformation that requires no scaling, just mirror and translate. Write a function that takes a pointer or reference to a TSPoint object, performs the shifting and returns the result in-situ.

Can you give me a link to the adafruit tutorial I might have been on the wrong document.

Maybe this link would help you: link to adafruit

Didn't spend time to check, but it seems to be what you're looking for.

This is exactly what I needed. Thank you.