Ceas si termometru cu afisaj LCD

Combinand informatiile din articolul despre senzorul DHT22 si cel despre modulul RTC DS3231 am creat un ceas cu termometru, afisarea facand-o pe displayul LCD prezentat in acest articol.

Toate conexiunile intre componente sunt cele prezentate in articolele de mai sus.

Sketch-ul folosit de mine la realizarea acestui ceas cu termometru este afisat mai jos:

#include <TFT_ST7735.h>
#include <SPI.h>
#include "DHT.h"
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float hum;
float temp; 

TFT_ST7735 tft = TFT_ST7735();
#define TFT_GREY 0x5AEB
 tmElements_t tm;

void setup() {
  dht.begin();
  tft.init();
  tft.setRotation(2);

  tft.fillRect(2, 2, 122, 20, TFT_CYAN);
  tft.setCursor(4, 4, 2);
  tft.setTextColor(TFT_RED);  
  tft.println("Ceas DS3231 ");
  
  tft.fillRect(2, 25, 122, 20, TFT_CYAN);
  tft.setCursor(4, 27, 2);
  tft.setTextColor(TFT_RED);  
  tft.println("si termometru");
  
  tft.fillRect(2, 48, 122,20, TFT_CYAN);
  tft.setCursor(4, 52, 2);
  tft.setTextColor(TFT_RED);
  tft.print("cu DHT22 si LCD");

  tft.fillRect(2, 75, 122,20, TFT_CYAN);
  tft.setCursor(4, 77, 2);
  tft.setTextColor(TFT_RED);
  tft.print("ST7735");
  delay(2000); 
}

void loop() {
  hum = dht.readHumidity();
  temp= dht.readTemperature();
  RTC.read(tm);
  
  //tft.fillScreen(TFT_GREY);
  tft.setTextSize(1);
  
  tft.fillRect(2, 2, 122, 20, TFT_WHITE);
  tft.setCursor(4, 4, 2);
  tft.setTextColor(TFT_BLUE);  
  tft.print("Temp.: ");
  tft.print(temp);
  tft.print(" ");
  tft.drawCircle(87, 6, 2, TFT_BLUE);
  tft.print("C");
  
  tft.fillRect(2, 25, 122,20, TFT_WHITE);
  tft.setCursor(4, 27, 2);
  tft.setTextColor(TFT_BLUE);
  tft.print("Umid.: ");
  tft.print(hum);
  tft.print(" %"); 
  
  tft.fillRect(2, 48, 122, 20, TFT_WHITE);
  tft.setTextColor(TFT_BLUE);
  tft.setCursor(4, 52, 2);
  printDigit(tm.Hour);
  tft.print(":");
  printDigit(tm.Minute);
  tft.print(":");
  printDigit(tm.Second);  

  tft.fillRect(2, 75, 122, 20, TFT_WHITE);
  tft.setTextColor(TFT_BLUE);
  tft.setCursor(4, 77, 2);
  tft.print(tm.Day);
  tft.print("/");
  tft.print(tm.Month);
  tft.print("/");
  tft.print(tmYearToCalendar(tm.Year));

  tft.fillRect(2, 100, 122, 20, TFT_WHITE);
  tft.setTextColor(TFT_BLUE);
  tft.setCursor(4, 102, 2);
  tft.print("electronicstore.ro"); 

  delay(1000);
}

int printDigit(int numar) {
  if (numar >= 0 && numar < 10) {
    tft.print('0');
  }
  tft.print(numar);
}

Mai jos puteti vedea si un filmulet cu montajul in functiune:

 

 

Autentificare