I bought a LCD TFT 2.8'' and, after a loooong googling, I get it running.
Now I have a problem and can't resolve it:
I draw a screen with one button and I want to press the button and display another screen.
For this I made two procedures with the screen 1 and screen 2 configuration. The curious is that if I call the Screen1 procedure, made a 3 seconds delay and call the Screen2 procedure in the void setup(void) everything works fine, I get the 1st screen, and after 3 seconds I get the 2nd Screen.
Now the problem is when I do this in the void loop(void) I don't get the second Screen. I know that the Screen2() procedure is called when I press the button, but the LCD don't display the Screen.
Anyone knows why?
This is the code I'm using:
#include <Adafruit_GFX.h>
#include "SWTFT.h"
#include "TouchScreen.h"
#include <stdint.h>
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define YP A1 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 6 // can be a digital pin
#define XP 7 // can be a digital pin
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
int screen = 1;
SWTFT tft;
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
pinMode(XM, OUTPUT);
digitalWrite(XM, LOW);
pinMode(YP, OUTPUT);
digitalWrite(YP, HIGH);
pinMode(YM, OUTPUT);
digitalWrite(YM, LOW);
pinMode(XP, OUTPUT);
digitalWrite(XP, HIGH);
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
Serial.print(F("Text "));
Serial.println(Screen1());
}
void loop(void) {
Point p = ts.getPoint();
int x=p.x;
int y=p.y;
Serial.println(" ");
Serial.print("P.X = ");
Serial.println(p.x);
Serial.print("P.Y = ");
Serial.println(p.y);
Serial.print("P.Z = ");
Serial.println(p.z);
delay(2000);
switch (screen) {
case 1:
if ((x > 400) && (x<800)) {
if ((y > 500) && (y < 800)) {
Serial.println("SCREEN 2-------");
Screen2();
}
}
break;
}
}
unsigned long Screen1() {
unsigned long start = micros();
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.setTextSize(2);
tft.setCursor(20, 10);
tft.setTextColor(RED, YELLOW);
tft.print("CONTROLO TEMPERATURA!");
tft.setCursor(10, 50);
tft.setTextColor(WHITE);
tft.print("Data: ");
tft.setTextColor(RED);
tft.print("2015-07-03 06:38");
tft.setCursor(10, 75);
tft.setTextColor(WHITE);
tft.print("Temperatura: ");
tft.setTextColor(RED);
tft.println("37.7 oC");
tft.setCursor(10, 100);
tft.setTextColor(WHITE);
tft.print("Humidade: ");
tft.setTextColor(RED);
tft.print("56 %");
tft.setCursor(10, 125);
tft.setTextColor(WHITE);
tft.print("Dias de func.: ");
tft.setTextColor(RED);
tft.print("3");
tft.fillRect(20, 150, 100, 50, RED);
tft.drawRect(20, 150, 100, 50, RED);
tft.setTextColor(WHITE);
tft.setCursor(50, 165);
tft.print("MENU");
return micros() - start;
}
unsigned long Screen2() {
tft.fillScreen(BLACK);
tft.setRotation(1);
tft.setTextSize(2);
tft.setCursor(20, 10);
tft.setTextColor(BLACK, GREEN);
tft.print("CONTROLO TEMPERATURA 2!");
tft.setCursor(10, 50);
tft.setTextColor(WHITE);
tft.print("Data: ");
tft.setTextColor(RED);
tft.print("2015-07-03 06:38");
tft.setCursor(10, 75);
tft.setTextColor(WHITE);
tft.print("Temperatura: ");
tft.setTextColor(RED);
tft.println("37.7 oC");
tft.setCursor(10, 100);
tft.setTextColor(WHITE);
tft.print("Humidade: ");
tft.setTextColor(RED);
tft.print("56 %");
tft.setCursor(10, 125);
tft.setTextColor(WHITE);
tft.print("Dias de func.: ");
tft.setTextColor(BLUE);
tft.print("3");
tft.fillRect(20, 150, 100, 50, BLUE);
tft.drawRect(20, 150, 100, 50, BLUE);
tft.setTextColor(WHITE);
tft.setCursor(50, 165);
tft.print("MENU");
}
thanks in advance