Skip to content

Instantly share code, notes, and snippets.

@dansku
Created July 17, 2013 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dansku/6016519 to your computer and use it in GitHub Desktop.
Save dansku/6016519 to your computer and use it in GitHub Desktop.
#include <SPI.h>
#include <dht.h>
dht DHT;
#define DHT22_PIN 8
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd1(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2);
byte D[8]={30,27,27,27,27,27,30,0};
byte A[8]={14,27,27,31,27,27,27,0};
byte T[8]={31,31,4,4,4,4,4,0};
byte E[8]={31,24,24,30,24,24,31,0};
byte heart[8]={0,10,31,31,14,4,0,0};
byte heart2[8]={0,0,10,31,31,14,4,0};
int coracao = 1;
// 61 days on 20 may
// days in may = 31, june = 30, july 20
int cdown = 0;
float temperatura;
float umidade;
void setup() {
lcd1.begin(16, 2);
lcd2.begin(16, 2);
lcd1.createChar(1, D);
lcd1.createChar(2, A);
lcd1.createChar(3, T);
lcd1.createChar(4, E);
lcd2.createChar(5, heart);
lcd2.createChar(6, heart2);
}
void loop() {
//---[TM]--//
tmElements_t tm;
int chk = DHT.read22(DHT22_PIN);
umidade = DHT.humidity;
temperatura = DHT.temperature;
if (RTC.read(tm)) {
//CountDown-----------------------
if(tm.Month == 5){ cdown = (31 + 20 + 30 - tm.Day);
}
else if(tm.Month == 6){
cdown = (20 + 30 - tm.Day);
}
else if(tm.Month == 7){
cdown = (20 - tm.Day);
}
//-------------------------
//----[LCD 01]---------//
// lcd1.print("Date: ");
lcd1.write(1);
lcd1.write(2);
lcd1.write(3);
lcd1.write(4);
lcd1.print(": ");
//Day
if(tm.Day < 10){ lcd1.print("0"); lcd1.print(tm.Day); } else { lcd1.print(tm.Day); }
lcd1.print("/");
if(tm.Month < 10){ lcd1.print("0"); lcd1.print(tm.Month); } else { lcd1.print(tm.Month); }
lcd1.print("/");
lcd1.print(tmYearToCalendar(tm.Year));
lcd1.setCursor(0, 1);
lcd1.print("Time: ");
//Hora
if(tm.Hour < 10){ lcd1.print("0"); lcd1.print(tm.Hour); } else { lcd1.print(tm.Hour); }
lcd1.print(":");
//Minutos
if(tm.Minute<10){ lcd1.print("0"); lcd1.print(tm.Minute); } else { lcd1.print(tm.Minute); }
lcd1.print(":");
//Segundo
if(tm.Second<10){ lcd1.print("0"); lcd1.print(tm.Second); } else{ lcd1.print(tm.Second); }
//----[LCD 02]---------//
lcd2.print("T:");
lcd2.print(temperatura);
lcd2.print("C H:");
lcd2.print(umidade);
lcd2.setCursor(0, 1);
lcd2.print("Countdown: ");
lcd2.print(cdown);
lcd2.print(" ");
if(coracao == 1){
lcd2.write(5);
coracao = 2;
}
else {
lcd2.write(6);
coracao = 1;
}
lcd1.setCursor(0, 0);
lcd2.setCursor(0, 0);
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(400);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment