mOskit
February 16, 2015, 3:28pm
1
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);
}
}
system
February 16, 2015, 3:32pm
2
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?
mOskit
February 16, 2015, 3:42pm
3
No Awol, this is taken out of the original example, so instead of floading serial with data it prints only when touched
mOskit
February 16, 2015, 3:44pm
4
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);
}
mOskit
February 16, 2015, 3:58pm
6
aaa:)
another great lesson.
mOskit
February 16, 2015, 4:52pm
7
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);
}
}
mOskit
February 16, 2015, 6:00pm
9
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?
mOskit
February 16, 2015, 6:25pm
11
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
mOskit
February 16, 2015, 9:03pm
12
I went thru and tried to get some answer and when myTFT.begin(); is in the code than the touch starts to be inoperative.