-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTEAMRnE_33B.ino
88 lines (66 loc) · 1.64 KB
/
STEAMRnE_33B.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
/*
* ROLE_CENTRAL
*/
#include <Wire.h>
#include <I2Cdev.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include "define.h"
tmElements_t tm;
void setup() {
Serial.begin(115200);
while(!Serial);
Wire.begin();
}
void loop() {
String Time = "N/A";
String Date = "N/A";
if(RTC.read(tm)) {
Date = tmYearToCalendar(tm.Year);
Date += '/';
save2digits(&Date, tm.Month);
Date += '/';
save2digits(&Date, tm.Day);
Time = "";
save2digits(&Time, tm.Hour);
Time += ':';
save2digits(&Time, tm.Minute);
Time += ':';
save2digits(&Time, tm.Second);
}
String output_p = "Time:(" + Date + '|' + Time + ")\n";
char* data = new char[output_p.length() + 1];
output_p.toCharArray(data, output_p.length() + 1);
Serial.write(data);
delete[] data;
data = 0;
delay(1000);
String x = "N/A", y = "N/A", z = "N/A";
if(Serial.available() > 0) {
delay(1000);
Serial.println(Serial.read());
if(Serial.find("data:(")) {
x = Serial.readStringUntil('|');
y = Serial.readStringUntil('|');
z = Serial.readStringUntil(')');
}
}
String output_r = "\"" + x + "\", \"" + y + "\", \"" + z + "\"";
Serial.println(output_r);
// time correcting
/*
String secNow = String(tm.Second);
char* timeNow = new char[secNow.length() + 1];
char* timeBefore = new char[secNow.length() + 1];
secNow.toCharArray(timeBefore, secNow.length() + 1);
for(;;) {
secNow = String(tm.Second);
secNow.toCharArray(timeNow, secNow.length() + 1);
if(!strcmp(timeBefore, timeNow))
break;
}
delete[] timeNow;
delete[] timeBefore;
timeNow = timeBefore = 0;
*/
}