-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathILI9341_RTC.ino
151 lines (128 loc) · 4.01 KB
/
ILI9341_RTC.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/////////////////////////////////////////////////////////////////
// Arduino ILI9341 RTC v1.01 //
// Get the latest version of the code here: //
/ http://educ8s.tv/arduino-2-8-ili9341-tutorial //
/////////////////////////////////////////////////////////////////
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include <SPI.h>
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
float maxTemperature=0;
float minTemperature=200;
char charMinTemperature[10];
char charMaxTemperature[10];
char timeChar[100];
char dateChar[50];
char temperatureChar[10];
float temperature = 0;
float previousTemperature = 0;
uint32_t old_ts;
String dateString;
int minuteNow=0;
int minutePrevious=0;
void setup(){
Serial.begin(9600);
tft.begin();
tft.setRotation(0);
tft.fillScreen(ILI9341_BLACK);
Wire.begin();
rtc.begin();
printText("TEMPERATURE", ILI9341_GREEN,20,130,3);
printText("MAX", ILI9341_RED,37,260,2);
printText("MIN", ILI9341_BLUE,173,260,2);
//setRTCTime();
}
void loop()
{
float temperature = rtc.getTemperature();
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();
if (old_ts == 0 || old_ts != ts) {
old_ts = ts;
minuteNow = now.minute();
if(minuteNow!=minutePrevious)
{
dateString = getDayOfWeek(now.dayOfWeek())+", ";
dateString = dateString+String(now.date())+"/"+String(now.month());
dateString= dateString+"/"+ String(now.year());
minutePrevious = minuteNow;
String hours = String(now.hour());
if(now.minute()<10)
{
hours = hours+":0"+String(now.minute());
}else
{
hours = hours+":"+String(now.minute());
}
hours.toCharArray(timeChar,100);
tft.fillRect(50,50,135,40,ILI9341_BLACK);
printText(timeChar, ILI9341_WHITE,55,55,4);
dateString.toCharArray(dateChar,50);
printText(dateChar, ILI9341_GREEN,8,5,2);
}
if(temperature != previousTemperature)
{
previousTemperature = temperature;
String temperatureString = String(temperature,1);
temperatureString.toCharArray(temperatureChar,10);
tft.fillRect(50,175,150,40,ILI9341_BLACK);
printText(temperatureChar, ILI9341_WHITE,50,180,4);
printText("o", ILI9341_WHITE,158,175,3);
printText("C", ILI9341_WHITE,180,180,4);
if(temperature>maxTemperature)
{
maxTemperature = temperature;
dtostrf(maxTemperature,5, 1, charMaxTemperature);
tft.fillRect(8,280,90,28,ILI9341_BLACK);
printText(charMaxTemperature, ILI9341_WHITE,8,290,2);
printText("o", ILI9341_WHITE,70,280,2);
printText("C", ILI9341_WHITE,85,290,2);
}
if(temperature < minTemperature)
{
minTemperature = temperature;
dtostrf(minTemperature,5, 1, charMinTemperature);
tft.fillRect(145,280,90,28,ILI9341_BLACK);
printText(charMinTemperature, ILI9341_WHITE,145,290,2);
printText("o", ILI9341_WHITE,207,280,2);
printText("C", ILI9341_WHITE,222,290,2);
}
}
}
delay(1000);
}
void setRTCTime()
{
DateTime dt(2018, 4, 2, 13, 13, 30, 1); // Year, Month, Day, Hour, Minutes, Seconds, Day of Week
rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above
}
void printText(char *text, uint16_t color, int x, int y,int textSize)
{
tft.setCursor(x, y);
tft.setTextColor(color);
tft.setTextSize(textSize);
tft.setTextWrap(true);
tft.print(text);
}
String getDayOfWeek(int i)
{
switch(i)
{
case 1: return "Monday";break;
case 2: return "Tuesday";break;
case 3: return "Wednesday";break;
case 4: return "Thursday";break;
case 5: return "Friday";break;
case 6: return "Saturday";break;
case 7: return "Sunday";break;
default: return "Monday";break;
}
}