can anyone help me!
the touch screene work nice, when i use the sd card , the value of x,y become -1
can anyone help me!
the touch screene work nice, when i use the sd card , the value of x,y become -1
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Now post your code properly.
#include <SdFat.h>
#include <UTFT.h>
#include <URTouch.h>
#include <UTFT_Buttons.h>
#include <UTFT_SdRaw.h>
#define SD_CHIP_SELECT 48 // SD chip select pin
// file system object
SdFat sd;
// Initialize display
UTFT myGLCD(ILI9341_16,40,41,43,44);
// Initialize touchscreen
URTouch myTouch(76, 46, 75, 74, 47);
UTFT_SdRaw myFiles(&myGLCD);
/*UTFT_Buttons myButtons(&myGLCD, &myTouch);
*/
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
int CURRENT_SCREEN = 0 ;
long xx, yy;
void setup()
{
Serial.begin(9600);
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setBrightness(255);
myGLCD.setContrast(16);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(SmallFont);
myGLCD.print("Initializing RTC DS3231", 1, 1);
delay(200);
myGLCD.print(" ok",200, 1);
myGLCD.print("Initializing DHT 22", 1, 11);
delay(200);
myGLCD.print(" ok", 200, 11);
myGLCD.print("Initializing RTC DS3231", 1, 22);
delay(200);
myGLCD.print(" ok", 200, 22);
myGLCD.print("Initializing Bluethouth HC-06", 1, 33);
delay(200);
myGLCD.print(" ok", 250, 33);
myGLCD.print("Initializing Ps2 Joystick", 1, 44);
delay(200);
myGLCD.print(" ok", 200, 44);
myGLCD.print("Initializing SD", 1, 55);
bool mysd = 0;
while (!mysd)
{
if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED))
{
myGLCD.print("Card failed, or not present",10,66);
myGLCD.print("Retrying....",10,77);
}
else
{
mysd = 1;
myGLCD.print("Card initialised ok",100,55);
delay(2000);
}
}
scr1 (); //function draw file.raw
}
void loop()
{
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
xx=myTouch.getX();
yy=myTouch.getY();
Serial.print("x=") ;
Serial.print(xx) ;
Serial.print("y=") ;
Serial.println(yy) ;
if ((xx>=135) && (xx<=185)) // Upper row
{
if ((yy>=80) && (yy<=130)) // Button: 1
{
waitForIt(135, 80, 185, 130);
scr2 ();
}
if ((yy>=150) && (yy<=200)) // Button: 2
{
waitForIt(135, 150, 185, 200);
scr3();
}
}
}
}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.