8
8
9
9
// Manual for library: http://lygte-info.dk/project/DisplayDriver%20UK.html
10
10
11
- dht DHT;
12
- const byte DHT11_PIN = 2 ;
13
-
14
- ThreeWire myWire (9 , 8 , 10 ); // IO, SCLK, CE
15
- RtcDS1302<ThreeWire> Rtc (myWire);
16
-
17
- const byte numberOfDigits = 4 ;
11
+ #define numberOfDigits 16
18
12
const byte dataPin = A4;
19
13
const byte clockPin = A5;
20
14
const byte loadPin = A2;
21
15
22
- LEDDisplayDriver display (dataPin, clockPin, loadPin);
16
+ LEDDisplayDriver display (dataPin, clockPin, true , numberOfDigits);
17
+ DISPLAY_INTR (display)
18
+
19
+ char dateTimeString[30];
20
+
21
+ dht DHT;
22
+ #define DHT11_PIN 2
23
+
24
+ ThreeWire myWire (9 , 8 , 10 ); // IO, SCLK, CE
25
+ RtcDS1302<ThreeWire> Rtc (myWire);
23
26
24
27
void setup () {
25
28
Serial.begin (9600 );
26
- Serial.println (" Thermo 14" );
27
- Rtc. Begin ();
29
+ Serial.println (" Thermo 14 compiled on " );
30
+
28
31
RtcDateTime compiled = RtcDateTime (__DATE__, __TIME__);
29
- printDateTime (compiled);
30
- Serial.println ();
32
+ getDateTimeString (compiled);
33
+ Serial.println (dateTimeString );
31
34
35
+ display.showText (" Hello thermo14" );
36
+ delay (2000 );
37
+
38
+ Serial.println (" hello serial thermo14" );
39
+ Rtc.Begin ();
32
40
if (!Rtc.IsDateTimeValid ()) {
33
41
// Common Causes:
34
42
// 1) first time you ran and the device wasn't running yet
@@ -50,8 +58,8 @@ void setup() {
50
58
51
59
RtcDateTime now = Rtc.GetDateTime ();
52
60
Serial.println (" RTC says datetime is:" );
53
- printDateTime (now);
54
- Serial.println ();
61
+ getDateTimeString (now);
62
+ Serial.println (dateTimeString );
55
63
if (now < compiled) {
56
64
Serial.println (" RTC is older than compile time! (Updating DateTime)" );
57
65
Rtc.SetDateTime (compiled);
@@ -63,59 +71,62 @@ void setup() {
63
71
}
64
72
65
73
66
- char displayBuffer[4 ] = {' ' , ' ' , ' ' , ' ' };
67
- char dateTimeString[20 ];
68
-
69
74
void loop () {
75
+ display.showText (" Time is" );
76
+ delay (2000 );
70
77
RtcDateTime now = Rtc.GetDateTime ();
71
- display.showTextScroll (" Date/time is... " );
72
- printDateTime (now);
73
- Serial.println ();
74
- display.showTextScroll (dateTimeString);
75
- delay (500 );
78
+ getDateTimeString (now);
79
+ display.showText (dateTimeString);
80
+ delay (2000 );
76
81
77
82
if (!now.IsValid ()) {
78
83
// Common Causes:
79
84
// 1) the battery on the device is low or even missing and the power line was disconnected
80
85
Serial.println (" RTC lost confidence in the DateTime!" );
86
+ display.showText (" CLOCK BAD!?" );
81
87
}
82
88
int chk = DHT.read11 (DHT11_PIN);
83
89
double c = DHT.temperature ;
84
90
if (c == -999 ) {
85
- display.showTextScroll (" Waiting for sensor...... " );
86
- delay (5000 );
91
+ display.showText (" Waiting for sensor" );
92
+ delay (2000 );
87
93
return ;
88
94
}
89
- display.showTextScroll (" Temperature is " );
90
- delay (300 );
95
+ display.showText (" Temperature: " );
96
+ delay (2000 );
91
97
Serial.println (c);
92
- display.clear ();
93
98
double f = (c * 9.0 / 5.0 ) + 32.0 ;
94
- display.showNum (f);
95
99
Serial.println (f);
100
+ display.clear ();
101
+ display.showNum2Left (f);
96
102
97
103
delay (5000 );
98
- display.showTextScroll (" RH is " );
104
+ display.showText (" RH is:" );
105
+ delay (2000 );
99
106
double rh = DHT.humidity ;
100
107
Serial.println (rh);
101
108
display.clear ();
102
- display.showNum (rh);
109
+ display.showNum2Left (rh); display. showChar ( 3 , ' % ' );
103
110
104
- delay (5000 );
111
+ delay (2000 );
105
112
}
106
113
107
114
108
115
#define countof (a ) (sizeof (a) / sizeof (a[0 ]))
109
116
110
- void printDateTime (const RtcDateTime& dt) {
117
+ void getDateTimeString (const RtcDateTime& dt) {
118
+ int hour = dt.Hour ();
119
+ if (hour > 12 ) {
120
+ hour -= 12 ;
121
+ }
111
122
snprintf_P (dateTimeString,
112
123
countof (dateTimeString),
113
- PSTR (" %02u/%02u/%04u %02u:%02u:%02u" ),
114
- dt.Month (),
115
- dt.Day (),
116
- dt.Year (),
117
- dt.Hour (),
124
+ // PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
125
+ PSTR (" %02u:%02u:%02u" ),
126
+ // dt.Month(),
127
+ // dt.Day(),
128
+ // dt.Year(),
129
+ hour,
118
130
dt.Minute (),
119
131
dt.Second () );
120
- Serial.print (dateTimeString);
121
132
}
0 commit comments