Hi Guys,
I am trying to create a GUI for a project i am working on, and have purchased a touchscreen to use with it. I have no idea how to code a touchscreen, and have been adjusting one of the examples that came with the screen. However, the example was in portrait, and i want it in landscape. I changed the line tft.setRotation(1), to 3, which changed the picture on the screen, however the touch part still thinks it is in portrait.
I think i have narrowed down the section of code relating to the touch, highlighted below, but cannot get it to work properly.
Can any of you help me please?
Thanks,
Chris
tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(BLACK);
// create buttons
for (uint8_t row=0; row<5; row++) {
for (uint8_t col=0; col<3; col++) {
buttons[col + row3].initButton(&tft, BUTTON_X+col(BUTTON_W+BUTTON_SPACING_X),
BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y), // x, y, w, h, outline, fill, text
BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row3], ILI9341_WHITE,
buttonlabels[col + row3], BUTTON_TEXTSIZE);
buttons[col + row*3].drawButton();
}
}
// create 'text field'
tft.drawRect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H, ILI9341_WHITE);
}
// Print something in the mini status bar with either flashstring
void status(const __FlashStringHelper *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
// or charstring
void status(char *msg) {
tft.fillRect(STATUS_X, STATUS_Y, 240, 8, ILI9341_BLACK);
tft.setCursor(STATUS_X, STATUS_Y);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(1);
tft.print(msg);
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop(void) {
/*TSPoint p;
p = ts.getPoint();
*/
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
// if sharing pins, you'll need to fix the directions of the touchscreen pins
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
// p = ts.getPoint();
/*
if (ts.bufferSize()) {
} else {
// this is our way of tracking touch 'release'!
p.x = p.y = p.z = -1;
}*/
// Scale from ~0->4000 to tft.width using the calibration #'s
/*
if (p.z != -1) {
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
Serial.print("("); Serial.print(p.x); Serial.print(", ");
Serial.print(p.y); Serial.print(", ");
Serial.print(p.z); Serial.println(") ");
}*/
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
// scale from 0->1023 to tft.width
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = (tft.height()-map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
}
// go thru all the buttons, checking if they were pressed
for (uint8_t b=0; b<15; b++) {
if (buttons**.contains(p.x, p.y))[/color] {**
** //Serial.print("Pressing: "); Serial.println(b);**
__ buttons**.press(true); // tell the button it is pressed**__
** } else {**
__ buttons**.press(false); // tell the button it is NOT pressed**
** }
}
// now we can ask the buttons if their state has changed**
** for (uint8_t b=0; b<15; b++) {**
if (buttons**.justReleased()) {
// Serial.print("Released: "); Serial.println(b);
buttons.drawButton(); // draw normal**
** }**__
__ if (buttons**.justPressed()) {
buttons.drawButton(true); // draw invert!**__
** // if a numberpad button, append the relevant # to the textfield**
** if (b >= 3) {**
** if (textfield_i < TEXT_LEN) {
textfield[textfield_i] = buttonlabels[0];
textfield_i++;
textfield[textfield_i] = 0; // zero terminate**