/**
 ****************************************************************************** 
 * @file     Text_and_Number_Display.ino
 * @brief    Set up a TFT display to show a cycling two-digit number.
 *           The program initializes the TFT screen, displays a color transition,
 *           and then continuously displays a number that increments from 00 to 99.
 * @version  V1.0
 * @date     2025-7-8
 * @license  MIT
 ****************************************************************************** 
 * Experiment Objective: Display a continuously incrementing two-digit number 
 *                       (00-99) on a TFT screen with a background color transition.
 *                       Demonstrates basic TFT display functionality and number formatting.
 *
 * Hardware Resources:
 * 1. TFT Display --> Connected via SPI (pins defined in User_Setup.h).
 *
 ****************************************************************************** 
 * Development Platform: ESP32-C3/S3 Development Board
 * Support Forum: service.waveshare.com
 * Company Website: www.waveshare.com
 *
 ****************************************************************************** 
 */

#include <SPI.h>
#include <TFT_eSPI.h>


#define device_A_CS 2 
#define device_B_CS 6 
#define BL1 1
#define BL2 3

TFT_eSPI tft = TFT_eSPI(); 

void setup() {

  pinMode (BL1,OUTPUT);
  pinMode (BL2,OUTPUT);
  pinMode (device_A_CS, OUTPUT);
  pinMode (device_B_CS, OUTPUT);

  digitalWrite(BL1,HIGH);
  digitalWrite(BL2,HIGH);
  
  tft.init();
  tft.fillScreen(TFT_BLUE);
  delay(1000);
  tft.fillScreen(TFT_RED);
  delay(1000);
  tft.fillScreen(TFT_GREEN);
  delay(1000);
  tft.fillScreen(0x04FF);
  tft.setTextColor(TFT_WHITE, 0x04FF); 

}

int number = 0;
void loop() {

  digitalWrite(device_A_CS,LOW);
  digitalWrite(device_B_CS,HIGH); 
  tft.setRotation(1);
  digitalWrite(device_B_CS,LOW);
  digitalWrite(device_A_CS,HIGH); 
  tft.setRotation(3);

  digitalWrite(device_A_CS,LOW);
  tft.drawString("Hello, Waveshare!", 30, 40, 2);
  String displayNumber = String(number);
  if (displayNumber.length() == 1) {
  displayNumber = "0" + displayNumber;
  }

  tft.drawString(displayNumber, 55, 80, 6);

  number++;
  if (number > 99) {
  number = 0; 
  }

  delay(1000);
}
