#define USE_DS1307 true
// Header file includes
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
//#include "Font_Data.h"
// inicio Font_Data.h
// Data file for user example user defined fonts
#pragma once
MD_MAX72XX::fontType_t numeric7SegDouble[] PROGMEM = {
0, // 0
0, // 1
0, // 2
0, // 3
0, // 4
0, // 5
0, // 6
0, // 7
0, // 8
0, // 9
0, // 10
0, // 11
0, // 12
0, // 13
0, // 14
0, // 15
0, // 16
0, // 17
0, // 18
0, // 19
0, // 20
0, // 21
0, // 22
0, // 23
0, // 24
0, // 25
0, // 26
0, // 27
0, // 28
0, // 29
0, // 30
0, // 31
2, 0, 0, // 32 - 'Space'
0, // 33 - '!'
0, // 34 - '"'
0, // 35 - '#'
0, // 36 - '$'
0, // 37 - '%'
0, // 38 - '&'
0, // 39 - '''
0, // 40 - '('
0, // 41 - ')'
0, // 42 - '*'
0, // 43 - '+'
0, // 44 - ','
0, // 45 - '-'
2, 48, 48, // 46 - '.'
0, // 47 - '/'
10, 62, 127, 192, 192, 192, 192, 192, 192, 127, 62, // 48 - '0'
10, 0, 0, 0, 0, 0, 0, 0, 0, 127, 62, // 49 - '1'
10, 62, 127, 193, 193, 193, 193, 193, 193, 64, 0, // 50 - '2'
10, 0, 65, 193, 193, 193, 193, 193, 193, 127, 62, // 51 - '3'
10, 0, 0, 1, 1, 1, 1, 1, 1, 127, 62, // 52 - '4'
10, 0, 64, 193, 193, 193, 193, 193, 193, 127, 62, // 53 - '5'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 54 - '6'
10, 0, 0, 0, 0, 0, 0, 0, 0, 127, 62, // 55 - '7'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 56 - '8'
10, 0, 64, 193, 193, 193, 193, 193, 193, 127, 62, // 57 - '9'
2, 6, 6, // 58 - ':'
0, // 59 - ';'
0, // 60 - '<'
0, // 61 - '='
0, // 62 - '>'
0, // 63 - '?'
0, // 64 - '@'
10, 62, 127, 1, 1, 1, 1, 1, 1, 127, 62, // 65 - 'A'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 66 - 'B'
10, 62, 127, 193, 193, 193, 193, 193, 193, 65, 0, // 67 - 'C'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 68 - 'D'
10, 62, 127, 193, 193, 193, 193, 193, 193, 65, 0, // 69 - 'E'
10, 62, 127, 1, 1, 1, 1, 1, 1, 1, 0, // 70 - 'F'
0, // 71 - 'G'
0, // 72 - 'H'
0, // 73 - 'I'
0, // 74 - 'J'
0, // 75 - 'K'
0, // 76 - 'L'
0, // 77 - 'M'
0, // 78 - 'N'
0, // 79 - 'O'
0, // 80 - 'P'
0, // 81 - 'Q'
0, // 82 - 'R'
0, // 83 - 'S'
0, // 84 - 'T'
0, // 85 - 'U'
0, // 86 - 'V'
0, // 87 - 'W'
0, // 88 - 'X'
0, // 89 - 'Y'
0, // 90 - 'Z'
0, // 91 - '['
0, // 92 - '\'
0, // 93 - ']'
0, // 94 - '^'
0, // 95 - '_'
0, // 96 - '`'
10, 62, 127, 1, 1, 1, 1, 1, 1, 127, 62, // 97 - 'a'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 98 - 'b'
10, 62, 127, 193, 193, 193, 193, 193, 193, 65, 0, // 99 - 'c'
10, 62, 127, 193, 193, 193, 193, 193, 193, 127, 62, // 100 - 'd'
10, 62, 127, 193, 193, 193, 193, 193, 193, 65, 0, // 101 - 'e'
10, 62, 127, 1, 1, 1, 1, 1, 1, 1, 0, // 102 - 'f'
0, // 103 - 'g'
0, // 104 - 'h'
0, // 105 - 'i'
0, // 106 - 'j'
0, // 107 - 'k'
0, // 108 - 'l'
0, // 109 - 'm'
0, // 110 - 'n'
0, // 111 - 'o'
0, // 112 - 'p'
0, // 113 - 'q'
0, // 114 - 'r'
0, // 115 - 's'
0, // 116 - 't'
0, // 117 - 'u'
0, // 118 - 'v'
0, // 119 - 'w'
0, // 120 - 'x'
0, // 121 - 'y'
0, // 122 - 'z'
0, // 123 - '{'
2, 255, 255, // 124 - '|'
0, // 125
0, // 126
0, // 127
0, // 128
0, // 129
0, // 130
0, // 131
0, // 132
0, // 133
0, // 134
0, // 135
0, // 136
0, // 137
0, // 138
0, // 139
0, // 140
0, // 141
0, // 142
0, // 143
0, // 144
0, // 145
0, // 146
0, // 147
0, // 148
0, // 149
0, // 150
0, // 151
0, // 152
0, // 153
0, // 154
0, // 155
0, // 156
0, // 157
0, // 158
0, // 159
2, 0, 0, // 160
0, // 161
0, // 162
0, // 163
0, // 164
0, // 165
0, // 166
0, // 167
0, // 168
0, // 169
0, // 170
0, // 171
0, // 172
0, // 173
2, 0, 0, // 174
0, // 175
10, 124, 254, 3, 3, 3, 3, 3, 3, 254, 124, // 176
10, 0, 0, 0, 0, 0, 0, 0, 0, 254, 124, // 177
10, 0, 2, 131, 131, 131, 131, 131, 131, 254, 124, // 178
10, 0, 130, 131, 131, 131, 131, 131, 131, 254, 124, // 179
10, 124, 254, 128, 128, 128, 128, 128, 128, 254, 124, // 180
10, 124, 254, 131, 131, 131, 131, 131, 131, 2, 0, // 181
10, 124, 254, 131, 131, 131, 131, 131, 131, 2, 0, // 182
10, 0, 2, 3, 3, 3, 3, 3, 3, 254, 124, // 183
10, 124, 254, 131, 131, 131, 131, 131, 131, 254, 124, // 184
10, 124, 254, 131, 131, 131, 131, 131, 131, 254, 124, // 185
2, 96, 96, // 186
0, // 187
0, // 188
0, // 189
0, // 190
0, // 191
0, // 192
10, 124, 254, 131, 131, 131, 131, 131, 131, 254, 124, // 193
10, 124, 254, 128, 128, 128, 128, 128, 128, 0, 0, // 194
10, 0, 0, 128, 128, 128, 128, 128, 128, 0, 0, // 195
10, 0, 0, 128, 128, 128, 128, 128, 128, 254, 124, // 196
10, 124, 254, 131, 131, 131, 131, 131, 131, 130, 0, // 197
10, 124, 254, 131, 131, 131, 131, 131, 131, 130, 0, // 198
0, // 199
0, // 200
0, // 201
0, // 202
0, // 203
0, // 204
0, // 205
0, // 206
0, // 207
0, // 208
0, // 209
0, // 210
0, // 211
0, // 212
0, // 213
0, // 214
0, // 215
0, // 216
0, // 217
0, // 218
0, // 219
0, // 220
0, // 221
0, // 222
0, // 223
0, // 224
10, 124, 254, 131, 131, 131, 131, 131, 131, 254, 124, // 225
10, 124, 254, 128, 128, 128, 128, 128, 128, 0, 0, // 226
10, 0, 0, 128, 128, 128, 128, 128, 128, 0, 0, // 227
10, 0, 0, 128, 128, 128, 128, 128, 128, 254, 124, // 228
10, 124, 254, 131, 131, 131, 131, 131, 131, 130, 0, // 229
10, 124, 254, 131, 131, 131, 131, 131, 131, 130, 0, // 230
0, // 231
0, // 232
0, // 233
0, // 234
0, // 235
0, // 236
0, // 237
0, // 238
0, // 239
0, // 240
0, // 241
0, // 242
0, // 243
0, // 244
0, // 245
0, // 246
0, // 247
0, // 248
0, // 249
0, // 250
0, // 251
2, 255, 255, // 252
0, // 253
0, // 254
0, // 255
};
MD_MAX72XX::fontType_t customFont[] PROGMEM = {
4, 127, 65, 65, 127, // 0 - '0'
4, 0, 66, 127, 64, // 1 - '1'
4, 121, 73, 73, 79, // 2 - '2'
4, 99, 73, 73, 119, // 3 - '3'
4, 15, 8, 8, 127, // 4 - '4'
4, 79, 73, 73, 121, // 5 - '5'
4, 127, 73, 73, 121, // 6 - '6'
4, 3, 1, 125, 3, // 7 - '7'
4, 119, 73, 73, 119, // 8 - '8'
4, 79, 73, 73, 127, // 9 - '9'
0, // 10
0, // 11
0, // 12
0, // 13
0, // 14
0, // 15
0, // 16
0, // 17
0, // 18
0, // 19
0, // 20
0, // 21
0, // 22
0, // 23
0, // 24
0, // 25
0, // 26
0, // 27
0, // 28
0, // 29
0, // 30
0, // 31
2, 0, 0, // 32 - 'Space'
1, 95, // 33 - '!'
3, 7, 0, 7, // 34 - '"'
5, 20, 127, 20, 127, 20, // 35 - '#'
5, 36, 42, 127, 42, 18, // 36 - '$'
5, 76, 44, 16, 104, 100, // 37 - '%'
8, 6, 6, 0, 56, 68, 68, 68, 40, // 38 - '&'
3, 8, 7, 3, // 39 - '''
3, 28, 34, 65, // 40 - '('
3, 65, 34, 28, // 41 - ')'
5, 42, 28, 127, 28, 42, // 42 - '*'
3, 16, 56, 16, // 43 - '+'
0, // 44 '
3, 16, 16, 16, // 45 - '-'
1, 64, // 46 - '.'
3, 64, 16, 4, // 47 - '/'
3, 124, 68, 124, // 48
3, 72, 124, 64, // 49
3, 116, 84, 92, // 50
3, 84, 84, 124, // 51
3, 28, 16, 124, // 52
3, 92, 84, 116, // 53
3, 124, 84, 116, // 54
3, 4, 116, 12, // 55
3, 108, 84, 108, // 56
3, 28, 20, 124, // 57
1, 40, // 58 - ':'
2, 128, 104, // 59 - ';'
4, 8, 20, 34, 65, // 60 - '<'
5, 20, 20, 20, 20, 20, // 61 - '='
4, 65, 34, 20, 8, // 62 - '>'
5, 2, 1, 89, 9, 6, // 63 - '?'
5, 62, 65, 93, 89, 78, // 64 - '@'
5, 124, 18, 17, 18, 124, // 65 - 'A'
5, 127, 73, 73, 73, 54, // 66 - 'B'
5, 62, 65, 65, 65, 34, // 67 - 'C'
5, 127, 65, 65, 65, 62, // 68 - 'D'
5, 127, 73, 73, 73, 65, // 69 - 'E'
5, 127, 9, 9, 9, 1, // 70 - 'F'
5, 62, 65, 65, 81, 115, // 71 - 'G'
5, 127, 8, 8, 8, 127, // 72 - 'H'
3, 65, 127, 65, // 73 - 'I'
5, 32, 64, 65, 63, 1, // 74 - 'J'
5, 127, 8, 20, 34, 65, // 75 - 'K'
5, 127, 64, 64, 64, 64, // 76 - 'L'
5, 127, 2, 28, 2, 127, // 77 - 'M'
5, 127, 4, 8, 16, 127, // 78 - 'N'
5, 62, 65, 65, 65, 62, // 79 - 'O'
5, 127, 9, 9, 9, 6, // 80 - 'P'
5, 62, 65, 81, 33, 94, // 81 - 'Q'
5, 127, 9, 25, 41, 70, // 82 - 'R'
5, 38, 73, 73, 73, 50, // 83 - 'S'
5, 3, 1, 127, 1, 3, // 84 - 'T'
5, 63, 64, 64, 64, 63, // 85 - 'U'
5, 31, 32, 64, 32, 31, // 86 - 'V'
5, 63, 64, 56, 64, 63, // 87 - 'W'
5, 99, 20, 8, 20, 99, // 88 - 'X'
5, 3, 4, 120, 4, 3, // 89 - 'Y'
5, 97, 89, 73, 77, 67, // 90 - 'Z'
3, 127, 65, 65, // 91 - '['
5, 2, 4, 8, 16, 32, // 92 - '\'
3, 65, 65, 127, // 93 - ']'
5, 4, 2, 1, 2, 4, // 94 - '^'
5, 64, 64, 64, 64, 64, // 95 - '_'
3, 3, 7, 8, // 96 - '`'
5, 32, 84, 84, 120, 64, // 97 - 'a'
5, 127, 40, 68, 68, 56, // 98 - 'b'
5, 56, 68, 68, 68, 40, // 99 - 'c'
5, 56, 68, 68, 40, 127, // 100 - 'd'
5, 56, 84, 84, 84, 24, // 101 - 'e'
4, 8, 126, 9, 2, // 102 - 'f'
5, 24, 164, 164, 156, 120, // 103 - 'g'
5, 127, 8, 4, 4, 120, // 104 - 'h'
3, 68, 125, 64, // 105 - 'i'
4, 64, 128, 128, 122, // 106 - 'j'
4, 127, 16, 40, 68, // 107 - 'k'
3, 65, 127, 64, // 108 - 'l'
5, 124, 4, 120, 4, 120, // 109 - 'm'
5, 124, 8, 4, 4, 120, // 110 - 'n'
5, 56, 68, 68, 68, 56, // 111 - 'o'
5, 252, 24, 36, 36, 24, // 112 - 'p'
5, 24, 36, 36, 24, 252, // 113 - 'q'
5, 124, 8, 4, 4, 8, // 114 - 'r'
5, 72, 84, 84, 84, 36, // 115 - 's'
4, 4, 63, 68, 36, // 116 - 't'
5, 60, 64, 64, 32, 124, // 117 - 'u'
5, 28, 32, 64, 32, 28, // 118 - 'v'
5, 60, 64, 48, 64, 60, // 119 - 'w'
5, 68, 40, 16, 40, 68, // 120 - 'x'
5, 76, 144, 144, 144, 124, // 121 - 'y'
5, 68, 100, 84, 76, 68, // 122 - 'z'
3, 8, 54, 65, // 123 - '{'
1, 119, // 124 - '|'
3, 65, 54, 8, // 125 - '}'
5, 2, 1, 2, 4, 2, // 126 - '~'
5, 60, 38, 35, 38, 60, // 127 - 'Hollow Up Arrow'
0, // 128
5, 12, 18, 178, 2, 4, // 129 - 'Arabic ?'
2, 96, 32, // 130 - 'Hamza'
3, 1, 125, 1, // 131 - 'Alef with madda above'
2, 123, 1, // 132 - 'Alef with hamza above'
6, 3, 29, 34, 162, 162, 124, // 133 - 'Waw with hamza above'
2, 192, 95, // 134 - 'Alef with hamza below'
7, 56, 68, 64, 67, 89, 84, 36, // 135 - 'Yeh with hamza above'
1, 127, // 136 - 'Alef'
6, 28, 34, 160, 32, 32, 28, // 137 - 'Beh'
5, 56, 69, 68, 69, 56, // 138 - 'Teh marbuta'
6, 56, 68, 65, 64, 65, 60, // 139 - 'Teh '
6, 56, 68, 64, 66, 65, 58, // 140 - 'Theh'
6, 64, 34, 34, 162, 34, 28, // 141 - 'Jeem'
6, 128, 68, 68, 68, 68, 56, // 142 - 'Hah'
6, 128, 68, 68, 69, 68, 56, // 143 - 'Khah'
3, 64, 68, 56, // 144 - 'Dal'
3, 64, 69, 56, // 145 - 'Thal'
2, 128, 124, // 146 - 'Reh'
2, 128, 125, // 147 - 'Zain'
9, 56, 68, 64, 64, 60, 64, 60, 64, 60, // 148 - 'Seen'
9, 56, 68, 64, 64, 61, 64, 61, 64, 61, // 149 - 'Sheen'
10, 56, 68, 64, 64, 60, 68, 68, 68, 68, 56, // 150 - 'Sad'
10, 56, 68, 64, 64, 60, 68, 68, 69, 68, 56, // 151 - 'Dad'
8, 64, 64, 126, 68, 68, 68, 68, 56, // 152 - 'Tah'
8, 64, 64, 126, 68, 68, 69, 68, 56, // 153 - 'Zah'
5, 184, 68, 68, 68, 72, // 154 - 'Ain'
5, 184, 68, 69, 68, 72, // 155 - 'Ghain'
0, // 156
0, // 157
0, // 158
0, // 159
0, // 160
1, 64, // 161 - 'Tatweel'
9, 56, 68, 64, 64, 72, 84, 85, 84, 56, // 162 - 'Feh'
9, 120, 132, 128, 128, 152, 165, 164, 165, 120, // 163 - 'Qaf'
7, 48, 72, 64, 67, 65, 64, 63, // 164 - 'Kaf'
6, 96, 144, 128, 128, 128, 127, // 165 - 'Lam'
7, 248, 4, 60, 68, 68, 68, 56, // 166 - 'Meem'
5, 56, 68, 64, 65, 60, // 167 - 'Noon'
5, 56, 68, 68, 68, 56, // 168 - 'Heh'
5, 28, 34, 162, 162, 124, // 169 - 'Waw'
7, 56, 68, 64, 64, 88, 84, 36, // 170 - 'Alef maksura'
7, 28, 34, 160, 32, 172, 42, 18, // 171 - 'Yeh'
0, // 172
0, // 173
0, // 174
0, // 175
7, 7, 5, 7, 56, 68, 68, 68, // 176
0, // 177
0, // 178
0, // 179
0, // 180
0, // 181
0, // 182
0, // 183
0, // 184
0, // 185
0, // 186
0, // 187
0, // 188
0, // 189
0, // 190
0, // 191
2, 48, 48, // 192 - 'Zero'
1, 126, // 193 - 'One'
4, 124, 2, 2, 2, // 194 - 'Two'
5, 126, 8, 6, 8, 6, // 195 - 'Three'
4, 52, 74, 74, 74, // 196 - 'Four'
5, 60, 66, 66, 66, 60, // 197 - 'Five'
4, 2, 2, 2, 124, // 198 - 'Six'
5, 190, 65, 65, 65, 34, // 199 - 'Seven'
5, 124, 2, 2, 2, 124, // 200 - 'Eight'
5, 12, 18, 18, 18, 124, // 201 - 'Nine'
0, // 202
0, // 203
0, // 204
0, // 205
0, // 206
0, // 207
0, // 208
0, // 209
0, // 210
0, // 211
0, // 212
0, // 213
0, // 214
0, // 215
0, // 216
0, // 217
0, // 218
0, // 219
0, // 220
0, // 221
0, // 222
0, // 223
0, // 224
0, // 225
0, // 226
0, // 227
0, // 228
0, // 229
0, // 230
5, 184, 68, 68, 68, 40, // 231
0, // 232
0, // 233
0, // 234
0, // 235
0, // 236
0, // 237
0, // 238
0, // 239
0, // 240
0, // 241
0, // 242
0, // 243
0, // 244
0, // 245
0, // 246
0, // 247
0, // 248
0, // 249
0, // 250
0, // 251
0, // 252
0, // 253
0, // 254
0, // 255
};
// fim Font_Data.h
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <MD_DS1307.h>
#include <Wire.h>
#include <SPI.h>
#include <DHT.h> /* DHT SENSOR LIBRARY BY ADAFRUIT */
//#include "Font_Data.h"
//#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_CLK_ZONES 2
#define ZONE_SIZE 12
#define ZONE_QNT 4
#define MAX_DEVICES (MAX_CLK_ZONES * ZONE_SIZE)
// ESP32 - SPI connection
#define CLK_PIN 18
#define DATA_PIN 23
#define CS_PIN 5
// DHT22 - AM2302
#define DHTPIN 4 // D4 - ESP32 DEVKIT V1
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define MAX_MESG 16
// Global Variables
char szMsgL[MAX_MESG];
char szMsgH[MAX_MESG];
char szTimeL[MAX_MESG];
char szTimeH[MAX_MESG];
char tmDHT[MAX_MESG];
char tmWeekDay[MAX_MESG];
uint32_t lastTime = 0;
uint32_t lastTimeDHT = 0;
uint32_t lastTimeweekDayMode = 0;
bool flasher = false;
bool weekDayMode = false;
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
DHT dht(DHTPIN, DHTTYPE);
class Zone {
private:
int id;
int mStart; // module start
int mEnd; // module end
MD_MAX72XX::fontType_t *pFont; // font reference
const char *pText; // text reference
textPosition_t align = PA_LEFT; // default position
textEffect_t effectIn = PA_PRINT; // default effIn
textEffect_t effectOut = PA_NO_EFFECT; // default effOut
uint16_t speed = 75;
uint16_t pause = 0;
void autoConfig() {
P.setZone(this->id, this->mStart, this->mEnd);
P.setFont(this->id, this->pFont);
P.displayZoneText(this->id, this->pText, this->align, this->speed, this->pause, this->effectIn, this->effectOut);
}
public:
Zone(int id, int mStart, int mEnd, MD_MAX72XX::fontType_t *pFont, const char *pText) {
this->id = id;
this->mStart = mStart;
this->mEnd = mEnd;
this->pFont = pFont;
this->pText = pText;
this->autoConfig();
}
Zone(int id, int mStart, int mEnd, MD_MAX72XX::fontType_t *pFont, const char *pText, textPosition_t align) {
this->id = id;
this->mStart = mStart;
this->mEnd = mEnd;
this->pFont = pFont;
this->pText = pText;
this->align = align;
this->autoConfig();
}
void setAlign(textPosition_t align) {
this->align = align;
this->autoConfig();
}
void setTextEffect(textEffect_t effectIn, textEffect_t effectOut) {
this->effectIn = effectIn;
this->effectOut = effectOut;
this->autoConfig();
}
};
// Global Functions
void getDHTData(char *psMsg);
void createHString(char *pH, char *pL);
void getDS1307Data(char *psTime, char *psDate, char *psWeekDay, bool f = true);
const char *dow2String(uint8_t code);
// Running
void setup(void) {
dht.begin(); // Inicializa o DHT22
for (byte i = 0; i < 4; i++) { // For MAX 7219 panel initialization error fix!
delay(100);
P.begin(ZONE_QNT);
}
Zone zone_Clock_LOWER(0, 6, 11, numeric7SegDouble, szTimeL);
Zone zone_Clock_UPPER(1, 18, 23, numeric7SegDouble, szTimeH);
Zone zone_Msg_LOWER(2, 0, 5, customFont, szMsgL, PA_CENTER);
Zone zone_Msg_UPPER(3, 12, 17, customFont, szMsgH, PA_CENTER);
zone_Msg_LOWER.setTextEffect(PA_SCROLL_UP, PA_NO_EFFECT);
RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
RTC.control(DS1307_12H, DS1307_OFF);
delay(100);
}
bool animationStatus(uint8_t qntZones) {
bool sts = true;
for (uint8_t z = 0; z < ZONE_QNT; z++) {
sts &= P.getZoneStatus(z);
}
return sts;
}
bool tempEff = false;
void loop(void) {
P.displayAnimate();
if (P.getZoneStatus(0) && P.getZoneStatus(1) && P.getZoneStatus(2) && P.getZoneStatus(3)) {
/* Handle WeekDayMode */
if (millis() - lastTimeweekDayMode >= 3000) { // 3s to change MSG
lastTimeweekDayMode = millis();
weekDayMode = !weekDayMode;
P.setTextEffect(2, PA_SCROLL_UP, PA_NO_EFFECT);
tempEff = true;
}
/* Handle data from DHT22 */
if (millis() - lastTimeDHT >= 5000) { // 5s to update sensor data
lastTimeDHT = millis();
getDHTData(tmDHT);
}
/* Handle data from DS1307 and Update display */
if (millis() - lastTime >= 1000) { // 1s to update display
lastTime = millis();
getDS1307Data(szTimeL, szMsgH, tmWeekDay, flasher);
createHString(szTimeH, szTimeL);
flasher = !flasher;
if (weekDayMode) {
// P.setFont(2, fontArabic);
strcpy(szMsgL, tmWeekDay);
} else {
// P.setFont(2, special);
strcpy(szMsgL, tmDHT);
}
if (!tempEff) {
P.setTextEffect(2, PA_PRINT, PA_NO_EFFECT);
}
tempEff = false;
P.displayReset();
P.setIntensity(0);
P.synchZoneStart();
}
}
}
// Functions
void getDHTData(char *psMsg) {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
sprintf(psMsg, "No Sensor!");
return;
}
sprintf(psMsg, "%.1f& %.1f%%", t, h);
}
const char *dow2String(uint8_t code) {
static const char *str[] = { "ERRO", "DOMINGO", "SEGUNDA", "TERÇA", "QUARTA", "QUINTA", "SEXTA", "SÁBADO" };
if (code > 7) code = 0;
return (str[code]);
}
void getDS1307Data(char *psTime, char *psDate, char *psWeekDay, bool f) {
do {
RTC.readTime();
} while (RTC.mm < 1 || RTC.mm > 12); // check erro.
sprintf(psTime, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
sprintf(psDate, "%02d/%02d/%04d", RTC.dd, RTC.mm, RTC.yyyy);
sprintf(psWeekDay, dow2String(RTC.dow));
}
void createHString(char *pH, char *pL) {
for (; *pL != '\0'; pL++)
*pH++ = *pL | 0x80; // offset character
*pH = '\0'; // terminate the string
}