/*  
* Free skecht.
* TFT ST7789 TO ESP32 BME280 17-09-2023  
*   
* Redefinition I2C for the BME280 code line 21 > 25
 */
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SPI.h>             // Arduino SPI library
#include <Wire.h>

// ST7789 TFT module connections
#define TFT_CS  15
#define TFT_DC   2
#define TFT_RST  4
#define TFT_SCL 18
#define TFT_SDA 23

//===== Redefinition I2C for the BME280.==
#define I2C_SDA 33
#define I2C_SCL 32
TwoWire I2CBME = TwoWire(0);
Adafruit_BME280 bme;
//========================================
#define SEALEVELPRESSURE_HPA (1005.00)// Mid. Europa
unsigned long delayTime;

// Initialize Adafruit ST7789 TFT library
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup(void) {
 Serial.begin(9600);
 Serial.println("TFT ST7789 TO ESP32 BME280 17-09-2023");

 I2CBME.begin(I2C_SDA, I2C_SCL, 100000);
 bool status;
 // default settings
 // (you can also pass in a Wire library object like &Wire2)
 status = bme.begin(0x76, &I2CBME);
 if (!status) {
   Serial.println("Could not find a valid BME280 sensor, check wiring!");
   while (1);
 }

 Serial.println("-- Default Test --");
 delayTime = 1000;


 // if the display has CS pin try with SPI_MODE0// Was spi mode 2
 tft.init(240, 320, SPI_MODE3);    // Init ST7789 display 240x240 pixel
 // if the screen is flipped, remove this command
 tft.setRotation(0);
 // text
 tft.fillScreen(ST77XX_BLUE);
 tft.invertDisplay(false);
 tft.setTextColor(ST77XX_RED);
 tft.setTextSize(2);
 tft.setCursor(0, 20);
 tft.println("HEHUI BME280 on TFT.");
 delay(4000);
}

///void loop() {
///  printValues();
///  delay(delayTime);
///}

void loop()
{
  tft.fillScreen(ST77XX_BLUE);
 tft.setTextColor(ST77XX_YELLOW);
 tft.setCursor(10, 5);
 tft.setTextSize(2);
 tft.print("Temp: ");
 tft.print(bme.readTemperature());
 tft.println(" *C");