Hi,
Is it possible to reset a part of this screen?TFT Shield specs
I have made it work but the time and date become after a while white bloks.
This is because the screen does not refresh and the pixels get white voor number 1 and then the pixels for number 3 get also white .. and so on. Is there a solution for this?
This is my code:
//////////////////////////////////////////////
// 2.8" TOUCH SCREEN DEMO //
// //
// http://www.educ8s.tv //
/////////////////////////////////////////////
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#include "pitches.h"
#include <Wire.h> //include Wire.h library
#include "RTClib.h" //include Adafruit RTC library
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 117
#define TS_MINY 109
#define TS_MAXX 945
#define TS_MAXY 915
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
boolean buttonEnabled = true;
RTC_DS3231 rtc; //Make a RTC DS3231 object
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
Serial.begin(115200);
//Serial.print("Starting...");
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
//Sets the code compilation time to RTC DS3231
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
tft.reset();
tft.begin(0x9341);
tft.setRotation(3);
tft.fillScreen(BLACK);
//Draw white frame
tft.drawRect(0,0,319,240,WHITE);
//Print "Welkom" Text
tft.setCursor(45,50);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.print("Welkom bij");
tft.setCursor(45,100);
tft.setTextColor(CYAN);
tft.setTextSize(4);
tft.print("STYLEMATHOT");
//Create Red Button
tft.fillRect(40,180,240,50, GREEN);
tft.drawRect(40,180,240,50,WHITE);
tft.setCursor(135,188);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.print("BEL");
}
void loop()
{
DateTime now = rtc.now();
tft.setCursor(5,15);
tft.setTextColor(WHITE);
tft.setTextSize(2);
//Print RTC time
tft.print(now.year(), DEC);
tft.print('/');
tft.print(now.month(), DEC);
tft.print('/');
tft.print(now.day(), DEC);
tft.print(" (");
tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
tft.print(") ");
tft.print(now.hour(), DEC);
tft.print(':');
tft.print(now.minute(), DEC);
tft.print(':');
tft.println(now.second(), DEC);
TSPoint p = ts.getPoint(); //Get touch point
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//if (p.z > ts.pressureThreshhold) {
//Serial.print("X = "); Serial.print(p.x);
//Serial.print("\tY = "); Serial.print(p.y);
//Serial.print("\n");
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);
if(p.x>40 && p.x<240 && p.y>180 && p.y<240 && buttonEnabled)// The user has pressed inside the red rectangle
{
buttonEnabled = false; //Disable button
//This is important, because the libraries are sharing pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//Erase the screen
tft.fillScreen(BLACK);
//Draw frame
tft.drawRect(0,0,319,240,WHITE);
tft.setCursor(15,70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("U wordt spoedig geholpen.");
tft.setCursor(25,120);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Bedankt voor uw bezoek.");
// hier bel laten afgaan draadloos
delay(3000);
software_Reset() ;
}
//}
}
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}