Thank you for always answering my questions. I have tested your code and function, but it does not display the exact time. All the same I would like to stay on my start code and just improve it finally to get the results that I wish.The tools I use are: a TFT LCD Resistiv Touchplatin (2.8 inch) Adafruit, a PmodRTCC and Arduino Mega.
I decided to go step by step now. Here is the code I wrote yesterday. I would like a reaction when you press the Start button. But alas my Start button does not work. Can you tell me or I made a mistake?
How can you program the window change when you touch the screen?
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
//#include <TouchScreen.h>
#include <Adafruit_STMPE610.h>
#include <Arduino.h>
#include <Wire.h> // this #include still required because the RTClib depends on it
#include "RTClib.h"
Adafruit_STMPE610 touch = Adafruit_STMPE610();
//Touchscreen X+ X- Y+ Y- pins
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 5 // can be a digital pin
#define XP 4 // can be a digital pin
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_Millis rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
boolean RecordOn = false;
#define FRAME_X 60
#define FRAME_Y 180
#define FRAME_W 201
#define FRAME_H 40
#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W FRAME_W
#define REDBUTTON_H FRAME_H
void drawFrame()
{
tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
}
boolean buttonStart = true;
boolean buttonFenster = true;
boolean buttonErweiterungen = true;
boolean buttonFenster1 = true;
boolean buttonSensordatenEinstellungen = true;
boolean buttonFenster2 = true;
boolean buttonFenster3 = true;
//boolean buttonFenster4 = true;
void StartBtn()
{
tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
tft.setCursor(REDBUTTON_X + 50 , REDBUTTON_Y + (REDBUTTON_H/3));
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(3);
tft.println("Start");
}
void setup () {
Serial.begin(9600);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
}
else {
Serial.println("Touchscreen started");
}
tft.begin(); // this returns the above results. below you can see how I replaced all this once i know which one I have...
tft.fillScreen(ILI9341_WHITE); //Set's LCD Back Ground as ILI9341_BLACK
tft.setRotation(1); // 3=landscape mode -w- row pins on right...
ts.begin();
StartBtn();
}
void loop () {
if (!ts.bufferEmpty())
{
TS_Point p = ts.getPoint();
// Scale using the calibration #'s
// and rotate coordinate system
p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.width());
p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.height());
int y = tft.height() - p.x;
int x = p.y;
if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
Serial.println("Start btn hit");
StartBtn();
}
}
}
DateTime now = rtc.now();
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(30, 20);
tft.println(now.year(), DEC);
Serial.print(now.year(), DEC);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(110, 20);
tft.println('/');
Serial.print('/');
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(140, 20);
tft.println(now.month(), DEC);
Serial.print(now.month(), DEC);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(170, 20);
tft.println('/');
Serial.print('/');
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(200, 20);
tft.println(now.day(), DEC);
Serial.print(now.day(), DEC);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(30, 70);
tft.println("(");
Serial.print("(");
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(70, 70);
tft.println(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(230, 70);
tft.println(" )");
Serial.print(") ");
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(30, 120);
tft.println(now.hour(), DEC);
Serial.print(now.hour(), DEC);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(70, 120);
tft.println(':');
Serial.print(':');
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(90, 120);
tft.println(now.minute(), DEC);
Serial.print(now.minute(), DEC);
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(130, 120);
tft.println(':');
Serial.print(':');
tft.setTextSize(3);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setCursor(150, 120);
tft.println(now.second(), DEC);
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
}