Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_GFX.h> // include Adafruit graphics library
- #include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library
- #include <DHT.h> // include DHT library
- #define TFT_RST 8 // TFT RST pin is connected to arduino pin 8
- #define TFT_CS 9 // TFT CS pin is connected to arduino pin 9
- #define TFT_DC 10 // TFT DC pin is connected to arduino pin 10
- // initialize ST7735 TFT library
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
- #define DHTPIN A0 // DHT11 data pin is connected to Arduino analog pin 0
- #define DHTTYPE DHT11 // DHT11 sensor is used
- DHT dht11(DHTPIN, DHTTYPE); // initialize DHT library
- void setup(void)
- {
- tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
- tft.fillScreen(ST7735_BLACK); // fill screen with black color
- tft.drawFastHLine(0, 50, tft.width(), ST7735_BLUE); // draw horizontal blue line at position (0, 50)
- tft.drawFastHLine(0, 102, tft.width(), ST7735_BLUE); // draw horizontal blue line at position (0, 102)
- tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // set text color to white and black background
- tft.setTextSize(1); // text size = 1
- tft.setCursor(4, 16); // move cursor to position (4, 16) pixel
- tft.print("ARDUINO + ST7735 TFT");
- tft.setCursor(22, 33); // move cursor to position (22, 33) pixel
- tft.print("+ DHT11 SENSOR");
- tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set text color to green and black background
- tft.setCursor(25, 61); // move cursor to position (25, 61) pixel
- tft.print("TEMPERATURE =");
- tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // set text color to yellow and black background
- tft.setCursor(34, 113); // move cursor to position (34, 113) pixel
- tft.print("HUMIDITY =");
- tft.setTextSize(2); // text size = 2
- // initialize DHT11 sensor
- dht11.begin();
- }
- char _buffer[7];
- // main loop
- void loop()
- {
- // read humidity
- byte humi = dht11.readHumidity();
- // read temperature
- byte temp = dht11.readTemperature();
- // print temperature (in °C)
- sprintf(_buffer, "%02u.0", temp);
- tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red and black background
- tft.setCursor(29, 78);
- tft.print(_buffer);
- tft.drawCircle(83, 80, 2, ST7735_RED); // print degree symbol ( ° )
- tft.setCursor(89, 78);
- tft.print("C");
- // print humidity (in %)
- sprintf(_buffer, "%02u.0 %%", humi);
- tft.setTextColor(ST7735_CYAN, ST7735_BLACK); // set text color to cyan and black background
- tft.setCursor(29, 130);
- tft.print(_buffer);
- delay(1000); // wait a second
- }
- // end of code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement