// UTFT_Bitmap (C)2013 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the drawBitmap()-function.
//
// This demo was made to work on the 320x240 modules.
// Any other size displays may cause strange behaviour.
//
// This program requires the UTFT library.
//
#include <DS1307.h>
#include <UTFT.h>
#include <EEPROM.h>
#define eeprom_address 0x00
#define eeprom_value 0x01
// Init the DS1307
DS1307 rtc(22, 23);
// Declare which fonts we will be using
extern uint8_t BigFont[];
UTFT myGLCD(TFT01_24_8,A5,A4,A3,A2); // Remember to change the model parameter to suit your display module!
unsigned long starttime;
int sxi;
int syi;
int mxi;
int myi;
int hxi;
int hyi;
int DHT11PIN=25;
int humidity;
int temperature;
int temp_humidity;
int temp_temperature;
int sectime=1;
char str_hum[10];
char str_temp[10];
unsigned long start_millis;
Time ds1307_time;
uint8_t temp_hour=0xFF;
uint8_t temp_min=0xFF;
uint8_t temp_sec=0xFF;
uint8_t temp_date=0xFF;
uint8_t temp_mon=0xFF;
uint16_t temp_year=0xFF;
uint8_t temp_dow=0xFF;
uint8_t format_hour=0xFF;
uint8_t temp_format_hour=0x00;
void setup()
{
byte value;
value = EEPROM.read(eeprom_address);
if(value != eeprom_value)
{
EEPROM.write(eeprom_address, eeprom_value);
// The following lines can be commented out to use the values already stored in the DS1307
rtc.setDOW(THURSDAY); // Set Day-of-Week to THURSDAY
rtc.setTime(15, 17, 0); // Set the time to 15:17:00 (24hr format)
rtc.setDate(25, 9, 2014); // Set the date to September 9th, 2014
}
myGLCD.InitLCD(LANDSCAPE);
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(255, 255, 255);
myGLCD.setFont(BigFont);
myGLCD.fillCircle(200,120,119);
myGLCD.setColor(0, 0, 0);
myGLCD.fillCircle(200,120,116);
myGLCD.setColor(255, 255, 255);
for(int a=0;a<12;a++)
{
int x1,x2,y1,y2;
x1 = 200+cos(PI*0-PI*a/6)*105;
x2 = 200+cos(PI*0-PI*a/6)*117;
y1 = 120-sin(PI*0-PI*a/6)*105;
y2 = 120-sin(PI*0-PI*a/6)*117;
myGLCD.drawLine(x1,y1,x2,y2);
}
for(int a=0;a<60;a++)
{
int x1,x2,y1,y2;
x1 = 200+cos(PI*0-PI*a/30)*112;
x2 = 200+cos(PI*0-PI*a/30)*117;
y1 = 120-sin(PI*0-PI*a/30)*112;
y2 = 120-sin(PI*0-PI*a/30)*117;
myGLCD.drawLine(x1,y1,x2,y2);
}
myGLCD.setColor(0, 255, 0);
myGLCD.print("^C", 50, 40,90);
myGLCD.print("%", 50, 225,90);
myGLCD.setColor(255, 0, 127);
myGLCD.print("ITEAD Clock", 75, 35,90);
start_millis = millis();
rtc.halt(false);
}
void loop()
{
if(millis()-start_millis>1000)
{
start_millis = millis();
// Send Day-of-Week
ds1307_time =rtc.getTime();
myGLCD.setColor(0, 0, 0);
sxi = 200+cos(PI*0-PI*temp_sec/30)*90;
syi = 120-sin(PI*0-PI*temp_sec/30)*90;
myGLCD.drawLine(200, 120, sxi, syi);
temp_sec = ds1307_time.sec;
myGLCD.setColor(0, 0, 255);
sxi = 200+cos(PI*0-PI*temp_sec/30)*90;
syi = 120-sin(PI*0-PI*temp_sec/30)*90;
myGLCD.drawLine(200, 120, sxi, syi);
if(temp_min != ds1307_time.min)
{
myGLCD.setColor(0, 0, 0);
mxi = 200+cos(PI*0-PI*temp_min/30)*70;
myi = 120-sin(PI*0-PI*temp_min/30)*70;
myGLCD.drawLine(200, 120, mxi, myi);
temp_min = ds1307_time.min;
myGLCD.setColor(0, 255, 0);
mxi = 200+cos(PI*0-PI*temp_min/30)*70;
myi = 120-sin(PI*0-PI*temp_min/30)*70;
myGLCD.drawLine(200, 120, mxi, myi);
}
else
{
myGLCD.setColor(0, 255, 0);
mxi = 200+cos(PI*0-PI*temp_min/30)*70;
myi = 120-sin(PI*0-PI*temp_min/30)*70;
myGLCD.drawLine(200, 120, mxi, myi);
}
if(temp_hour != ds1307_time.hour)
{
if(temp_hour>12)
{
format_hour =1;
}
else
{
format_hour =0;
}
myGLCD.setColor(0, 0, 0);
hxi = 200+cos(PI*0-PI*temp_hour/6)*50;
hyi = 120-sin(PI*0-PI*temp_hour/6)*50;
myGLCD.drawLine(200, 120, hxi, hyi);
temp_hour = ds1307_time.hour;
myGLCD.setColor(255, 0, 0);
hxi = 200+cos(PI*0-PI*temp_hour/6)*50;
hyi = 120-sin(PI*0-PI*temp_hour/6)*50;
myGLCD.drawLine(200, 120, hxi, hyi);
}
else
{
myGLCD.setColor(255, 0, 0);
hxi = 200+cos(PI*0-PI*temp_hour/6)*50;
hyi = 120-sin(PI*0-PI*temp_hour/6)*50;
myGLCD.drawLine(200, 120, hxi, hyi);
}
myGLCD.setColor(0, 255, 0);
if(temp_dow != ds1307_time.dow)
{
temp_dow = ds1307_time.dow;
myGLCD.print(rtc.getDOWStr(FORMAT_SHORT), 20, 0,90);
}
// Send date
if(temp_date != ds1307_time.date)
{
temp_date = ds1307_time.date;
myGLCD.print(rtc.getDateStr(), 20, 80,90);
}
// Send time
if(temp_format_hour!=format_hour)
{
temp_format_hour=format_hour;
if(temp_format_hour==0)
myGLCD.print("AM", 50, 108,90);
else if(temp_format_hour==1)
myGLCD.print("PM", 50, 108,90);
}
//read dht11
int chk = dht11_read(DHT11PIN);
if(chk==0)
{
if(temp_humidity !=humidity)
{
temp_humidity = humidity;
itoa(humidity,str_hum,10);
//myGLCD.print(" ", 50, 0,90);
myGLCD.print(str_temp, 50, 0,90);
}
if(temp_temperature !=temperature)
{
temp_humidity = temperature;
itoa(temperature,str_temp,10);
//myGLCD.print(" ", 50, 180,90);
myGLCD.print(str_hum, 50, 180,90);
}
}
}
}
int dht11_read(int pin)
{
// BUFFER TO RECEIVE
uint8_t bits[5];
uint8_t cnt = 7;
uint8_t idx = 0;
// EMPTY BUFFER
for (int i=0; i< 5; i++) bits[i] = 0;
// REQUEST SAMPLE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delay(18);
digitalWrite(pin, HIGH);
delayMicroseconds(40);
pinMode(pin, INPUT);
// ACKNOWLEDGE or TIMEOUT
unsigned int loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return -2;
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return -2;
// READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT
for (int i=0; i<40; i++)
{
loopCnt = 10000;
while(digitalRead(pin) == LOW)
if (loopCnt-- == 0) return -2;
unsigned long t = micros();
loopCnt = 10000;
while(digitalRead(pin) == HIGH)
if (loopCnt-- == 0) return -2;
if ((micros() - t) > 40) bits[idx] |= (1 << cnt);
if (cnt == 0) // next byte?
{
cnt = 7; // restart at MSB
idx++; // next byte!
}
else cnt--;
}
// WRITE TO RIGHT VARS
// as bits[1] and bits[3] are allways zero they are omitted in formulas.
humidity = bits[0];
temperature = bits[2];
uint8_t sum = bits[0] + bits[2];
if (bits[4] != sum) return -1;
return 0;
}
Comments