// OneBitDisplay ST7305 TFT Demo Sketch for ESP32-S3
// Displays "Hello world!" sequentially with auto-wrap

#include <SPI.h>
#include <OneBitDisplay.h>

ONE_BIT_DISPLAY lcd;

// Define GPIO pins for ESP32-S3 and TFT connection.
// IMPORTANT: Adjust these pin numbers according to your specific ESP32-S3 development board's pinout.
// Example values (please verify with your board's pinout diagram):
#define TFT_CS      15   // Chip Select (CS) pin
#define TFT_MOSI    13   // Master Out Slave In (MOSI) pin
#define TFT_SCK     14   // Serial Clock (SCK) pin
#define TFT_DC      4    // Data/Command (DC) pin
#define TFT_RES     5    // Reset (RES) pin
#define TFT_LED     -1   // Backlight LED pin, -1 if not used or controlled externally

// Screen resolution
#define SCREEN_WIDTH  122
#define SCREEN_HEIGHT 250

// SPI communication frequency (40MHz is a common starting point for TFTs on ESP32-S3)
#define SPI_FREQUENCY 40000000 

void setup() {
  Serial.begin(115200);
  Serial.println("Initializing ST7305 TFT with OneBitDisplay on ESP32-S3...");

  // Set SPI pins for the display
  lcd.setSPIPins(TFT_CS, TFT_MOSI, TFT_SCK, TFT_DC, TFT_RES, TFT_LED);
  
  // Initialize the display (LCD_ST7305 type, SPI frequency)
  lcd.SPIbegin(LCD_ST7305, SPI_FREQUENCY); 

  Serial.println("Display initialized successfully!");

  // Allocate a back buffer for drawing operations (recommended for larger screens/complex drawing)
  lcd.allocBuffer(); 
  
  // Set display rotation (0, 90, 180, 270 degrees)
  lcd.setRotation(0); 

  // Fill screen with black background
  lcd.fillScreen(OBD_WHITE); 

  // Set text color to white
  lcd.setTextColor(OBD_BLACK); 
  
  // Set font size
  lcd.setFont(FONT_16x16); // Using 8x8 font for better fit on screen

  // Enable text wrapping
  lcd.setTextWrap(true); 

  // Set initial cursor position
  lcd.setCursor(0, 0); 
  
  // Initial display update
  lcd.display(); 
} 

void loop() {
  // Display "Hello world! "
  lcd.print("EarlySpring! ");
  int succ = lcd.display(); // Update display to show the new text
  //Serial.println(succ);
  delay(1000); // Wait for 1 second
}