-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.ino
226 lines (171 loc) · 4.31 KB
/
sketch.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <IRremote.h>
#include <RTClib.h>
#include <Wire.h>
RTC_DS1307 RTC;
IRrecv IR(3);
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8
#define SPEED_TIME 75
#define PAUSE_TIME 0
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
#define mills 60000;
// Clock
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
char D1Text[20] = "";
char D2Text[20] = "";
void resetDisplay(){
P.displayReset(0);
P.displayReset(1);
}
//-----------------RTC CLOCK------------
void getTime(DateTime now) {
uint8_t h = now.hour() > 12 ? now.hour()-12 : now.hour();
sprintf(D1Text, "%d:%02d", h, now.minute());
sprintf(D2Text, "%02d", now.second());
}
//-----------------RTC CLOCK-------------
void setup(void) {
IR.enableIRIn();
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");// This will reflect the time that your sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
delay(1000);
}
P.begin(2);
P.setInvert(false);
P.setZone(0, 0, 3);
P.setZone(1, 4, 7);
P.displayZoneText(0, D1Text, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(1, D2Text, PA_CENTER, SPEED_TIME, 1000, PA_PRINT, PA_NO_EFFECT);
}
//---------------countdown -- timer---------------
//timer variables
unsigned long countdownStartTime = 0;
unsigned long countdownDuration = 0;
//start
void startCountdown() {
countdownStartTime = millis();
}
//setTime
int h = 0, m = 0;
bool next = false;
void setTime() {
countdownDuration = ((h*60) + m) * mills;
sprintf(D1Text, "%d:%02d", h, m);
next ? sprintf(D2Text, "MIN") : sprintf(D2Text, "HR");
}
// timer
void countDown() {
if(countdownStartTime != 0) {
unsigned long currentTime = millis();
if(currentTime - countdownStartTime >= countdownDuration) {
countdownStartTime = 0;
strcpy(D1Text, "Time");
strcpy(D2Text, "UP!");
} else {
unsigned long remainingTime = countdownDuration - (currentTime - countdownStartTime);
int hours = remainingTime / 3600000;
int minutes = (remainingTime % 3600000) / 60000;
int seconds = (remainingTime % 60000) / 1000;
sprintf(D1Text, "%d:%02d", hours, minutes);
sprintf(D2Text, "%02d", seconds);
}
}
}
//-----------------countdown -- timer-------------------
int scene = 0;
void RemoteController() {
if (IR.decode()) {
long long key = IR.decodedIRData.decodedRawData;
Serial.println(IR.decodedIRData.decodedRawData, HEX);
switch (key) {
case 0x57A8FF00: // play
Serial.println("Play");
if(countdownDuration == 0) {
scene = 1;
} else {
Serial.println(countdownDuration);
startCountdown();
scene = 2;
}
break;
case 0x3DC2FF00: // reset
Serial.println("Reset");
countdownDuration = 0;
countdownStartTime = 0;
h=0;
m=0;
scene = 0;
break;
case 0x6F90FF00:
Serial.println("NEXT");
next = true;
break;
case 0x1FE0FF00:
Serial.println("PREV");
next = false;
break;
case 0xFD02FF00:
Serial.println("+");
next ? m++ : h++;
setTime();
break;
case 0x6798FF00:
Serial.println("-");
if(next && m) m--;
if(!next && h) h--;
setTime();
break;
case 0x9768FF00: //zero
// resetDisplay();
scene = 0;
break;
case 0xCF30FF00: //one
// resetDisplay();
scene = 1;
break;
case 0xE718FF00: //two
// resetDisplay();
scene = 2;
break;
// case 0x857AFF00: //three
// scene = 3;
// break;
// case 0x4FB0FF00: //cancel
// break;
default:
Serial.println("Something messy!");
}
delay(100);
IR.resume();
}
}
void loop(void)
{
DateTime now = RTC.now();
P.displayAnimate();
RemoteController();
resetDisplay();
switch(scene) {
case 0:
getTime(now);
break;
case 1:
setTime();
break;
case 2:
countDown();
break;
default:
Serial.println("Nothing!");
getTime(now);
}
}