Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_I2CDevice.h>
- #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
- #include <SPI.h> // Arduino SPI library
- #define TFT_MOSI 23 // SDA Pin on ESP32
- #define TFT_SCLK 18 // SCL Pin on ESP32
- #define TFT_CS 5 // Chip select control pin
- #define TFT_DC 17 // Data Command control pin
- #define TFT_RST 4 // Reset pin (could connect to RST pin)
- // Initialize Adafruit ST7789 TFT library
- Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
- unsigned long cur_time, old_time;
- int counter = 0;
- char _buffer[7];
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- tft.init(240, 320, SPI_MODE2);
- tft.setRotation(3);
- tft.fillScreen(ST77XX_WHITE);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if (cur_time - old_time > 1000) {
- counter++;
- int Humi = random(50, 80);
- // read temperature in degrees Celsius
- int Temp = random(34, 40);
- // print temperature (in °C)
- tft.setTextColor(ST77XX_RED, ST77XX_WHITE); // set text color to red with black background
- if (Temp < 0) // if temperature < 0
- sprintf(_buffer, "-%02u.%1u", (abs(Temp) / 10) % 100, abs(Temp) % 10);
- else // temperature >= 0
- sprintf(_buffer, "Vol: %02u.%1u", (Temp / 10) % 100, Temp % 10);
- tft.setTextSize(3);
- tft.setCursor(26, 71);
- tft.print(_buffer);
- // print humidity (in %)
- tft.setTextColor(ST77XX_CYAN, ST77XX_WHITE); // set text color to cyan and black background
- sprintf(_buffer, "Cur: %02u.%1u", (Humi / 10) % 100, Humi % 10);
- tft.setCursor(26, 171);
- tft.print(_buffer);
- old_time = millis();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement