UTOUCH what am i missing

Hi
Trying to get this working but i only receve x319 y239 from serial and touchscreen don`t react on touch.
Any advice??
pins are all digital.

//TOUCH//  
#include <UTouch.h>
UTouch  myTouch( 6, 5, 4, 3, 2);

int x, y;

void setup()
{
  Serial.begin(9600);

  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW);

}
void loop()
{
  if (myTouch.dataAvailable())
    delay(100);
  {

    myTouch.read();
    x=myTouch.getX();
    y=myTouch.getY();
    Serial.print("x: ");
    Serial.print(x);
    Serial.print(" y: ");
    Serial.println(y);
    delay(100);
  }
}
  if (myTouch.dataAvailable())
    delay(100);
  {

    myTouch.read();
    x=myTouch.getX();
    y=myTouch.getY();

You're reading data whether or not there's data to read - is that intentional?

No Awol, this is taken out of the original example, so instead of floading serial with data it prints only when touched

Magic things just happend…
for some reason this started to print correct data

//TOUCH//  
#include <UTouch.h>
UTouch  myTouch( 6, 5, 4, 3, 2);

int x, y;

void setup()
{
  Serial.begin(9600);

  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW);

}
void loop()
{
  if (myTouch.dataAvailable())
    
  { 
    myTouch.read();   
    x=myTouch.getX();
    y=myTouch.getY();
    Serial.print("x: ");
    Serial.print(x);
    Serial.print(" y: ");
    Serial.println(y);
    delay(100);
  }
}

An IF statement will do whatever comes immediately after it.

So,

if (myTouch.dataAvailable())
delay(100); <= this is the first thing the compiler sees after the IF statement

{ <= from here down, is not governed by the IF statement
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
Serial.print("x: “);
Serial.print(x);
Serial.print(” y: ");
Serial.println(y);
delay(100);
}

However with this,

if (myTouch.dataAvailable())

{ <= this is what the compiler sees after the IF statement, so it will do everything in the brackets
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
Serial.print("x: “);
Serial.print(x);
Serial.print(” y: ");
Serial.println(y);
delay(100);
}

aaa:)
another great lesson.

ok, while the previous code for the touch it self works fine, it don`t make much effect while the screen is running.
Am i having conflict here??

#include <SPI.h> 
#include <ILI9341_due_gText.h>
#include <ILI9341_due.h>

#include "fonts\Arial_bold_14.h"

#include <UTouch.h>
UTouch  myTouch( 6, 5, 4, 3, 2);

#define TFT_CS 53
#define TFT_DC 9
#define TFT_RESET 8
ILI9341_due myTFT(TFT_CS, TFT_DC, TFT_RESET);

int x, y;

void setup()
{
  Serial.begin(9600);

  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_LOW);

  bool result = myTFT.begin();

  Serial.print("TFT begin successful: ");
  Serial.println(result ? "YES" : "NO");

  myTFT.fillScreen(ILI9341_BLUE);
  myTFT.setRotation(iliRotation270);

  ILI9341_due_gText t1(&myTFT);
  t1.defineArea(100, 110, 220, 130);
  t1.selectFont(Arial_bold_14);
  t1.setFontLetterSpacing(5);
  t1.setFontColor(ILI9341_WHITE, ILI9341_BLUE);
  t1.drawString("Hello World", gTextAlignMiddleCenter);
}

void loop()
{

  {
    if (myTouch.dataAvailable())

    { 
      myTouch.read();   
      x=myTouch.getX();
      y=myTouch.getY();
      Serial.print("x: ");
      Serial.print(x);
      Serial.print(" y: ");
      Serial.println(y);
      delay(100);
    }
  }
}

You need to clean up your code.

void loop()
{
    if (myTouch.dataAvailable())
    { 
      myTouch.read();   
      x=myTouch.getX();
      y=myTouch.getY();
      Serial.print("x: ");
      Serial.print(x);
      Serial.print(" y: ");
      Serial.println(y);
      delay(100);
    }
}

Isnt that the case to share spi?

UTouch doesn't use SPI, it just needs those 5 pins that you set in the constructor.

BTW, that library requires you to calibrate the touch pad. Were you able to do so?

i didnt have to do it to use without the tft. as soon as you ad utouch to the spi screen y axis has no responze and x someimes print 155 no matter where you touch. So wired

I went thru and tried to get some answer and when myTFT.begin(); is in the code than the touch starts to be inoperative.