Keypad switch data entry won't switch to Landscape [SOLVED]


I have a KUMAN 3.5" TFT with Touchscreen on a M2ga2560.

My application uses the screen in Landscape mode. I have a sample code for a keypad in Portrait, which I’m trying to switch to Landscape as well and change the keypad form factor from 3x5 to 2x7.

I managed to get it to 2 rows of 7 keys without a problem. When I change tft.setRotation(0) to (1), it displays the buttons correctly, but I need to touch the screen in the location of the portrait mode in order to get a reading.

The code is attached. I suspect the problem is in the following section, but there are too many likely permutations for meto figure this out.


    p.x = p.x + p.y;       
    p.y = p.x - p.y;           
    p.x = p.x - p.y;   
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); //change width to height
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0)); //change height to width x2


Do I change the all the x’x to y’s, do I permutate the height and the width, do I do both…

Also, can you recommend a read-up on touchscreen code? I was actually developing these late 90’s, but there’s too much calcification in my brain to retrieve that info now.

Cheers (3.76 KB)

Quick Follow up to clarify:

As I said, I managed to change the layout to a 2x7 matrix, which reads (for now) with setRotation(0)

S C E 1 2 3
4 5 6 7 8 9

in sr(0), the touch screen ligns up.

When I set sr(1), the above displays rotates CCW by 90 degrees, the touch screen stays put.

After further digging, I saw a post from Wasserman, I believe, who suggests that i change the definitions of the pins as follows

#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin


#define XM A2  // must be an analog pin, use "An" notation!
#define YP A3  // must be an analog pin, use "An" notation!
#define XP 8   // can be a digital pin
#define YM 9   // can be a digital pin

When I do this, rather than a 90 degree rotation, I get a mirror image along the 7 buttons:

S C E 1 2 3 for the Display
4 5 6 7 8 9

4 5 6 7 8 9
S C E 1 2 3 for the Touch screen.

No matter how I permutate those definitions, I can't get it to work...


OK, I did some more trouble shooting with the sketch and the touch screen.

In the end, it was the fact that the sketch had MIN/MAX values that were too far out of calibration.

I recalibrated and used a section of the sketch that was commented out. All clear now.