Trying to write to MCUFriend 68090 after reading touch input

Hardware:

  • Mega2560
  • MCUFriend 68090

Attached is my sketch.
My goal is to read the input from the temperature +/- touch regions on the screen (this works), adjust the value stored in the desiredTemp variable (this part works) and then update the display with the new desiredTemp value (this part doesn't work). I'm assuming this is because A1 is shared between the LCD write and the touchscreen X- input.
I've not dealt with this type of problem, so I'm hoping someone can steer me in the write direction, and my google-fu is apparently failing on trying to solve this.

Looking at the Touchscreen_Calibr_native.ino sketch included with MCUFriend_kbv, do I have to setup loops where I am in read mode for a period of time and then in write mode?

944_climate_control.ino (21.5 KB)

Your problem is because the Touch Pins are shared with the TFT

    //Just a quick enable of reading the touchpoint to trigger my issue.
    TSPoint tp = ts.getPoint();
    pinMode(XM, OUTPUT);  //.kbv restore XM, XP after calling Touch functions
    pinMode(YP, OUTPUT);   //.kbv because Touch library left them as INPUT
    if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE)
    {
        xpos = map(tp.y, TS_LEFT, TS_RT, 0, 320);
        ypos = map(tp.x, TS_TOP, TS_BOT, 0, 240);
    }

Look at the example sketches. They calibrate in PORTRAIT mode.
If you rotate the screen, you have to "rotate" the Touch values. Look at the Touch_Shield_new.ino
example. Experiment with it. e.g. alter the rotation to LANDSCAPE or PORTRAIT_REV. It should still work 100%.

Most projects set the rotation once in setup() and it never alters.

David.

Hey David,
I ran the calibration, copied the values, and believe I set up the rotation properly based on the serial monitor text... Again I think?

const int XP = 7, XM = A1, YP = A2, YM = 6;                       //240x320 ID=0x6809
const int TS_LEFT = 135, TS_RT = 928, TS_TOP = 141, TS_BOT = 924; //Landscape

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

uint16_t xpos, ypos;

followed up with the following in loop()

  TSPoint tp = ts.getPoint();
  if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE)
  {
    xpos = map(tp.y, TS_LEFT, TS_RT, 0, 320);
    ypos = map(tp.x, TS_TOP, TS_BOT, 0, 240);
  }

If I get your code correctly, switching the pins back to "output" mode right after getPoint(), I'll be back in write mode for the screen, correct?

This topic was automatically closed after 120 days. New replies are no longer allowed.