prenticedavid / MCUFRIEND_kbv

MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields
Other
360 stars 178 forks source link

TFT LCD 2.4" ILI 0x9341 not working with DateTime class #223

Open OPiElix opened 1 year ago

OPiElix commented 1 year ago

As soon as I write in the loop() a DateTime object (no matter where), the TFT doesn't load (it remains white). Here is my he code:

#include <MCUFRIEND_kbv.h>
#include <Adafruit_GFX.h>   // Hardware-specific library
#include "RTClib.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

MCUFRIEND_kbv tft;
RTC_DS3231 rtc;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);     
  Serial.println("setup started");
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }      
  //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  uint16_t ID = tft.readID();  
  Serial.print("ID = 0x");
  Serial.println(ID, HEX);
  if (ID == 0xD3D3) ID = 0x9481; // write-only shield
  tft.begin(ID);
  Serial.println("TFT begun");
  tft.fillScreen(BLACK);
  tft.setRotation(3);  
  Serial.println("exit setup, enter loop()");
}

void loop() {
  // put your main code here, to run repeatedly:
  //  tft.setTextColor(YELLOW, BLACK);
  //DateTime now = rtc.now(); //uncommented not letting the TFT load
  //Serial.println(now.hour());  // same as above
  Serial.println("entered loop");  
  tft.setTextSize(3);
  tft.setCursor(0, 0);
  Serial.println("starting welcome screen");
  tft.println("hello world!");  
  tft.setTextSize(2);
  Serial.println("relocating cursor");  
  tft.setCursor(0, 50);
  tft.println("Welcome To TFT Clock ");  
  delay(2000);
  Serial.println("ended welcome screen");  
  //tft.fillScreen(BLACK);  
  tft.setCursor(50, 50);
  //tft.print(now.hour(), DEC);  
  Serial.println("time shown");
  delay(3000);
}

(If you need me to add something else just say it) Thanks, Opilite