Skip to content

Commit bd2eb1a

Browse files
committed
Got it mostly working with 16 digits
Still a bug in the scroll routine. Some kind of buffer overflow. Avoid scroll for now.
1 parent 49df6ac commit bd2eb1a

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

thermo14/LEDDisplayDriver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//#define _USE_TIMER4_ // Supported on Mega2560 & Mega32U4
4747
//#define _USE_TIMER5_ // Supported on Mega2560
4848

49-
#define MAX_DIGITS 8 // Used to reserve frame buffer
49+
#define MAX_DIGITS 16 // Used to reserve frame buffer
5050

5151
// Limits how fast the pins change state
5252
// Using 10 gives slow and stable signals, 1 is the fastest with any delay and 0 is crazy fast when _FAST_CLOCK_ is enabled
@@ -89,7 +89,7 @@
8989

9090
// Display types that needs a 3. pin, i.e. load
9191
// The condition is reversed because most displays use 3 pins
92-
#if !(defined(_TM1637_) || defined(_TM1637_6DX_) || defined(_TM1637_COLON_)|| defined(_HC164_) || defined(_HT16K33_8D_) || defined(_HT16K33_14SEG_8D_) || defined(_HT16K33_14SEG_8D_) || defined(_HT16K33_4D_))
92+
#if !(defined(_TM1637_) || defined(_TM1637_6DX_) || defined(_TM1637_COLON_)|| defined(_HC164_) || defined(_HT16K33_8D_) || defined(_HT16K33_14SEG_8D_) || defined(_HT16K33_14SEG_4D_) || defined(_HT16K33_4D_))
9393
#define _DATA_BIDIRECTIONAL_
9494
#define _USE_LOAD_
9595
#endif

thermo14/thermo14.ino

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,35 @@
88

99
// Manual for library: http://lygte-info.dk/project/DisplayDriver%20UK.html
1010

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
1812
const byte dataPin = A4;
1913
const byte clockPin = A5;
2014
const byte loadPin = A2;
2115

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);
2326

2427
void setup() {
2528
Serial.begin(9600);
26-
Serial.println("Thermo 14");
27-
Rtc.Begin();
29+
Serial.println("Thermo 14 compiled on");
30+
2831
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
29-
printDateTime(compiled);
30-
Serial.println();
32+
getDateTimeString(compiled);
33+
Serial.println(dateTimeString);
3134

35+
display.showText("Hello thermo14");
36+
delay(2000);
37+
38+
Serial.println("hello serial thermo14");
39+
Rtc.Begin();
3240
if (!Rtc.IsDateTimeValid()) {
3341
// Common Causes:
3442
// 1) first time you ran and the device wasn't running yet
@@ -50,8 +58,8 @@ void setup() {
5058

5159
RtcDateTime now = Rtc.GetDateTime();
5260
Serial.println("RTC says datetime is:");
53-
printDateTime(now);
54-
Serial.println();
61+
getDateTimeString(now);
62+
Serial.println(dateTimeString);
5563
if (now < compiled) {
5664
Serial.println("RTC is older than compile time! (Updating DateTime)");
5765
Rtc.SetDateTime(compiled);
@@ -63,59 +71,62 @@ void setup() {
6371
}
6472

6573

66-
char displayBuffer[4] = {' ', ' ', ' ', ' '};
67-
char dateTimeString[20];
68-
6974
void loop() {
75+
display.showText("Time is");
76+
delay(2000);
7077
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);
7681

7782
if (!now.IsValid()) {
7883
// Common Causes:
7984
// 1) the battery on the device is low or even missing and the power line was disconnected
8085
Serial.println("RTC lost confidence in the DateTime!");
86+
display.showText("CLOCK BAD!?");
8187
}
8288
int chk = DHT.read11(DHT11_PIN);
8389
double c = DHT.temperature;
8490
if (c == -999) {
85-
display.showTextScroll("Waiting for sensor......");
86-
delay(5000);
91+
display.showText("Waiting for sensor");
92+
delay(2000);
8793
return;
8894
}
89-
display.showTextScroll("Temperature is ");
90-
delay(300);
95+
display.showText("Temperature:");
96+
delay(2000);
9197
Serial.println(c);
92-
display.clear();
9398
double f = (c * 9.0 / 5.0) + 32.0;
94-
display.showNum(f);
9599
Serial.println(f);
100+
display.clear();
101+
display.showNum2Left(f);
96102

97103
delay(5000);
98-
display.showTextScroll("RH is ");
104+
display.showText("RH is:");
105+
delay(2000);
99106
double rh = DHT.humidity;
100107
Serial.println(rh);
101108
display.clear();
102-
display.showNum(rh);
109+
display.showNum2Left(rh); display.showChar(3, '%');
103110

104-
delay(5000);
111+
delay(2000);
105112
}
106113

107114

108115
#define countof(a) (sizeof(a) / sizeof(a[0]))
109116

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+
}
111122
snprintf_P(dateTimeString,
112123
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,
118130
dt.Minute(),
119131
dt.Second() );
120-
Serial.print(dateTimeString);
121132
}

0 commit comments

Comments
 (0)