#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7796S.h>
#include <U8g2_for_Adafruit_GFX.h>
#include "colors.h"
#define TFT_CS1 5
#define TFT_CS2 6
#define TFT_DC 7
#define TFT_RST 4
#define TFT_SCLK 12 // SCL
#define TFT_MOSI 11 // SDA
#define TFT_MISO 13
// Utwórz obiekty TFT. Używamy konstruktora, który akceptuje wskaźnik SPI.
//Adafruit_ST7796S tft1 = Adafruit_ST7796S(&SPI, TFT_CS1, TFT_DC, TFT_RST);
//Adafruit_ST7796S tft2 = Adafruit_ST7796S(&SPI, TFT_CS2, TFT_DC, TFT_RST);
Adafruit_ST7796S tft1(TFT_CS1, TFT_DC, TFT_RST);
Adafruit_ST7796S tft2(TFT_CS2, TFT_DC, TFT_RST);
// Obiekty U8g2_for_Adafruit_GFX
U8G2_FOR_ADAFRUIT_GFX u8g2_1;
U8G2_FOR_ADAFRUIT_GFX u8g2_2;
//U8G2_FOR_ADAFRUIT_GFX u8g2;
void setup() {
Serial.begin(115200);
pinMode(TFT_CS1, OUTPUT);
pinMode(TFT_CS2, OUTPUT);
// Zainicjuj sprzętowy interfejs SPI na niestandardowych pinach dla ESP32
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI);
tft1.init(320, 480, 0, 0, ST7796S_BGR);
tft1.setRotation(0);
tft1.fillScreen(TFT_BLACK);
tft1.fillRect( 10, 10, 50, 50, TFT_RED);
tft1.fillRect(110, 10, 50, 50, TFT_GREEN);
tft1.fillRect(210, 10, 50, 50, TFT_BLUE);
tft1.drawRect(0, 0, tft1.width(), tft1.height(), TFT_BLUE);
// --- Inicjalizacja Tft2 ---
// RÓWNIEŻ Używamy init z parametrem BGR
tft2.init(320, 480, 0, 0, ST7796S_BGR);
tft2.setRotation(0);
tft2.fillScreen(TFT_BLACK);
tft2.fillRect( 10, 100, 50, 50, TFT_RED);
tft2.fillRect(110, 100, 50, 50, TFT_GREEN);
tft2.fillRect(210, 100, 50, 50, TFT_BLUE);
tft2.drawRect(0, 0, tft2.width(), tft2.height(), TFT_BLUE);
tft1.setTextColor(ST77XX_WHITE);
tft2.setTextColor(ST77XX_WHITE);
// --- U8g2 dla Tft1 ---
u8g2_1.begin(tft1);
u8g2_1.setFont(u8g2_font_unifont_te);
u8g2_1.setFontMode(0);
u8g2_1.setBackgroundColor(TFT_BLACK);
u8g2_1.setForegroundColor(TFT_WHITE);
u8g2_1.setCursor(50, 190);
u8g2_1.print("ĄąĆćĘꣳŃńÓ󌜯żŹź, ST7796! a");
// --- U8g2 dla Tft2 ---
u8g2_2.begin(tft2);
u8g2_2.setFont(u8g2_font_unifont_te);
u8g2_2.setFontMode(0);
u8g2_2.setBackgroundColor(TFT_BLACK);
u8g2_2.setForegroundColor(TFT_WHITE);
u8g2_2.setCursor(50, 190);
u8g2_2.print("ĄąĆćĘꣳŃńÓ󌜯żŹź, ST7796! b");
}
void loop() {
}