Interfacing with TFT Screen using mcufriend Lib

Dear Sirs,

Greetings!!

Here was trying to use MCUFriend TFT Code to display on TFT.This code is working smmothly on 16x2 LCD.
Now try to use on TFT,but having challenges when I tried to mix TFT & Project code.TFT allow to display desired things on Screen for
hardly 2 ms then screen bacome blank with White background.

Need your guideline & Please help me.

  1. Project Code
  2. TFT code
  3. My efforts (Code) are attached

Thanks

Kind Regards.

Dino_T

#include <Wire.h>
#include <EEPROM.h>
#include <RTClib.h>
#define ON 0
#define OFF 1
DateTime now;

LiquidCrystal_I2C lcd(0x27, 20, 4);
RTC_DS3231 rtc;   // ??
RTC_DS1307 RTC;   // ??
int starthr = 19, startmin = 0, offhr = 7, offmin = 0; //default time
int HOUR, MINUT, SECOND, DAY, MONTH, YEAR;

const int buttonPin = 2;   //Pin2 is always Interrupt Pin (Green/ModeChange)
const int lightonLed = 8;  //Green Led
const int lightoffLed = 9; //Red Led

#define btn4 3      // Press Yellow Button First to Set On/Off Time Menu
#define btn1 6      // Blue Button to SET  Hrs (Only Works Once)
#define btn2 5      // White Button  to SET  Minutes  (Seems OK)
#define btn3 4      // When desired time filled then Press Grey Button

#define relay 7     //Blue led


int nob = A0;
int val = 0;
int val1 = 0;
int path = 1;
int a = 1;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;  //20

int on_hour = 21;
int on_minute = 38;
int on_second = 00;

int off_hour = 21;
int off_minute = 36;
int off_second = 10;

int c_hour = 00;
int c_minute = 00;
int c_second = 00;

int onOrOffFlag = ON;

// void showDate(void);
void showTime(void);
// void showDay(void);

void loadHandler(int, int , int , int , int , int , int , int , int );

typedef struct userTime
{
  int temp_hour;
  int temp_minute;
  int temp_second;
} userTime_t;
unsigned char checkLessThanOrEqual(userTime_t , userTime_t);

void setup ()
{
Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Have");    
  lcd.setCursor(0, 1);
  lcd.print("Great");
  lcd.setCursor(0, 2);
  lcd.print("Luck)");
  delay(5000);
 
pinMode(buttonPin, INPUT_PULLUP);
pinMode(lightonLed,OUTPUT);
pinMode(lightoffLed,OUTPUT);
pinMode(relay,OUTPUT);
pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
pinMode(btn3, INPUT_PULLUP);
pinMode(btn4, INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(buttonPin), button_ISR, CHANGE);
 
if (! rtc.begin())
{
Serial.println("Couldn't find RTC Module");
while (1);
}
 
if (rtc.lostPower())   
{
Serial.println("RTC lost power, lets set the time!");
rtc.adjust(DateTime(2022, 10, 9, 21 , 35, 00));          
}  

//Setting on/off time as 00 if not set earlier
if(EEPROM.read(0)>25){
  EEPROM.write(0,starthr);
  EEPROM.write(1,startmin);
  EEPROM.write(2,offhr);
  EEPROM.write(3,offmin);
}
}

TFT Code

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#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 PURPLE 0x780F


void setup(void)
{

  uint16_t ID = tft.readID();

  if (ID == 0xD3D3) ID = 0x9486;
  tft.begin(ID);
  tft.setRotation(0);
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(2);

  // testing();
  tft.setTextSize(2);
  tft.setCursor(15, 5);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Welcome to");

  tft.setTextSize(2);
  tft.setCursor(15, 30);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Cafe");

  tft.setTextSize(2);
  tft.setCursor(15, 55);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Have");

  tft.setTextSize(2);
  tft.setCursor(15, 80);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Great");

  tft.setTextSize(2);
  tft.setCursor(15, 150);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Taste");

  tft.setTextSize(2);
  tft.setCursor(15, 175);
  tft.setTextColor(GREEN, BLACK);
  tft.print("of Tea ");

  tft.setTextSize(2);
  tft.setCursor(15, 200);
  tft.setTextColor(GREEN, BLACK);
  tft.print("& Cofee");
  delay(3000);

  tft.fillScreen(BLACK);

  tft.fillRect(50, 5, 185, 22, PURPLE);
  tft.setCursor(52, 7);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("X");

  tft.fillRect(50, 30, 185, 22, PURPLE);
  tft.setCursor(52, 32);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Y");

  tft.fillRect(50, 55, 185, 22, PURPLE);
  tft.setCursor(52, 57);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Z");

  tft.fillRect(50, 80, 185, 22, PURPLE);
  tft.setCursor(52, 82);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("A");

  tft.fillRect(50, 105, 185, 22, PURPLE);
  tft.setCursor(52, 107);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("B");

  tft.fillCircle(10, 12, 8, GREEN);
  tft.fillCircle(10, 37, 8, RED);
  tft.fillCircle(10, 62, 8, RED);
  tft.fillCircle(10, 87, 8, GREEN);
  tft.fillCircle(10, 112, 8, GREEN);
  tft.fillRect(5, 140, 230, 175, GREEN);
}
void loop(void)
{

}

My effort

#include <Wire.h>
#include <EEPROM.h>
//******************************
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#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 PURPLE 0x780F
//******************************
#include <RTClib.h>
#define ON 0
#define OFF 1
DateTime now;

LiquidCrystal_I2C lcd(0x27, 20, 4);
RTC_DS3231 rtc;   // ??
RTC_DS1307 RTC;   // ??
int starthr = 19, startmin = 0, offhr = 7, offmin = 0; //default time
int HOUR, MINUT, SECOND, DAY, MONTH, YEAR;

const int buttonPin = 2;   //Pin2 is always Interrupt Pin (Green/ModeChange)
const int lightonLed = 8;  //Green Led
const int lightoffLed = 9; //Red Led

#define btn4 3      // Press Yellow Button First to Set On/Off Time Menu
#define btn1 6      // Blue Button to SET  Hrs (Only Works Once)
#define btn2 5      // White Button  to SET  Minutes  (Seems OK)
#define btn3 4      // When desired time filled then Press Grey Button

#define relay 7     //Blue led


int nob = A0;
int val = 0;
int val1 = 0;
int path = 1;
int a = 1;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;  //20

int on_hour = 21;
int on_minute = 38;
int on_second = 00;

int off_hour = 21;
int off_minute = 36;
int off_second = 10;

int c_hour = 00;
int c_minute = 00;
int c_second = 00;

int onOrOffFlag = ON;

// void showDate(void);
void showTime(void);
// void showDay(void);

void loadHandler(int, int , int , int , int , int , int , int , int );

typedef struct userTime
{
  int temp_hour;
  int temp_minute;
  int temp_second;
} userTime_t;
unsigned char checkLessThanOrEqual(userTime_t , userTime_t);

void setup ()
{
  Serial.begin(9600);
  //  lcd.init();
  //  lcd.backlight();
  //  lcd.setCursor(0, 0);
  //  lcd.print("Have");
  //  lcd.setCursor(0, 1);
  //  lcd.print("Great");
  //  lcd.setCursor(0, 2);
  //  lcd.print("Luck)");
  //  delay(5000);

  uint16_t ID = tft.readID();

  if (ID == 0xD3D3) ID = 0x9486;
  tft.begin(ID);
  tft.setRotation(0);
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW, BLACK);
  tft.setTextSize(2);

  // testing();
  tft.setTextSize(2);
  tft.setCursor(15, 5);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Welcome to");

  tft.setTextSize(2);
  tft.setCursor(15, 30);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Cafe");

  tft.setTextSize(2);
  tft.setCursor(15, 55);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Have");

  tft.setTextSize(2);
  tft.setCursor(15, 80);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Great");

  tft.setTextSize(2);
  tft.setCursor(15, 150);
  tft.setTextColor(GREEN, BLACK);
  tft.print("Taste");

  tft.setTextSize(2);
  tft.setCursor(15, 175);
  tft.setTextColor(GREEN, BLACK);
  tft.print("of Tea ");

  tft.setTextSize(2);
  tft.setCursor(15, 200);
  tft.setTextColor(GREEN, BLACK);
  tft.print("& Cofee");
  delay(3000);

  tft.fillScreen(BLACK);

  tft.fillRect(50, 5, 185, 22, PURPLE);
  tft.setCursor(52, 7);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("X");

  tft.fillRect(50, 30, 185, 22, PURPLE);
  tft.setCursor(52, 32);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Y");

  tft.fillRect(50, 55, 185, 22, PURPLE);
  tft.setCursor(52, 57);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("Z");

  tft.fillRect(50, 80, 185, 22, PURPLE);
  tft.setCursor(52, 82);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("A");

  tft.fillRect(50, 105, 185, 22, PURPLE);
  tft.setCursor(52, 107);
  tft.setTextColor(WHITE);
  tft.setTextSize(2);
  tft.print("B");

  tft.fillCircle(10, 12, 8, GREEN);
  tft.fillCircle(10, 37, 8, RED);
  tft.fillCircle(10, 62, 8, RED);
  tft.fillCircle(10, 87, 8, GREEN);
  tft.fillCircle(10, 112, 8, GREEN);
  tft.fillRect(5, 140, 230, 175, GREEN);

  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(lightonLed, OUTPUT);
  pinMode(lightoffLed, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  pinMode(btn2, INPUT_PULLUP);
  pinMode(btn3, INPUT_PULLUP);
  pinMode(btn4, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(buttonPin), button_ISR, CHANGE);

  if (! rtc.begin())
  {
    Serial.println("Couldn't find RTC Module");
    while (1);
  }

  if (rtc.lostPower())
  {
    Serial.println("RTC lost power, lets set the time!");
    rtc.adjust(DateTime(2022, 10, 9, 21 , 35, 00));
  }

  //Setting on/off time as 00 if not set earlier
  if (EEPROM.read(0) > 25) {
    EEPROM.write(0, starthr);
    EEPROM.write(1, startmin);
    EEPROM.write(2, offhr);
    EEPROM.write(3, offmin);
  }
}

Hello david_2018 Sir

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.