-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTEAMRnE_31.ino
88 lines (71 loc) · 1.69 KB
/
STEAMRnE_31.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
#define DEBUG true
#include "def.h"
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
MPU6050 mpu;
tmElements_t tm;
int16_t ax, ay, az, gx, gy, gz;
int vx, vy, vz, fx, fy, fz;
String Time = "N/A";
String acc = "";
String output = "";
int _wait = 0;
void setup() {
Serial.begin(115200);
p(" Setting up Serial Communication with baudrate 115200... done.\n Waiting for response... ");
while (!Serial);
p("done.\n Setting up Wire System... ");
Wire.begin();
p("done.\n Setting up MPU6050... ");
mpu.initialize();
p("done.\n Waiting for response... ");
while (!mpu.testConnection()){
wait(1);
_wait++;
Serial.println(_wait);
}
p("done.\n ");
Serial.write("+++");
Serial.write("AT+ROLE=?\r\n");
Serial.write("AT+BIND=?\r\n");
/*
p("Trying to connect to Central... ");
Serial.write("test\n");
if(Serial.available() > 0) {
asdf
}
*/
}
void loop() {
Time = "N/A";
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
fx = vx = (gx + 300) / 200 + 2;
fy = vy = (gz - 100) / 200 + 2;
fz = vz = (gz - 600) / 200;
acc = String(fx) + '|' +
String(fy) + '|' +
String(fz);
if (RTC.read(tm)) {
Time = tmYearToCalendar(tm.Year);
Time += '/';
save2digits(&Time, tm.Month);
Time += '/';
save2digits(&Time, tm.Day);
Time += ' ';
save2digits(&Time, tm.Hour);
Time += ':';
save2digits(&Time, tm.Minute);
Time += ':';
save2digits(&Time, tm.Second);
}
output = "data:(" + Time + '|' + acc + ")\n";
char* data = new char[output.length() + 1];
output.toCharArray(data, output.length() + 1);
Serial.write(data);
delete[] data;
data = 0;
wait(1);
}