1#include <SD.h>
2#include <Wire.h>
3
4int16_t accelerometer_x, accelerometer_y, accelerometer_z;
5int16_t gyro_x, gyro_y, gyro_z;
6
7void setup() {
8 Serial.begin(9600);
9 Wire.begin();
10 Wire.beginTransmission(MPU_ADDRESS);
11 Wire.write(0x6B);
12 Wire.write(0);
13 Wire.endTransmission(true);
14 if (SD.begin(4)) {}
15 else if (!SD.begin(4)) {
16 Serial.println("ESD:404");
17 return;
18 }
19}
20
21void loop() {
22 Wire.beginTransmission(MPU_ADDRESS);
23 Wire.write(0x3B);
24 Wire.endTransmission(false);
25 Wire.requestFrom(MPU_ADDR, 7 * 2, true);
26 accelerometer_x = Wire.read() << 8 | Wire.read();
27 accelerometer_y = Wire.read() << 8 | Wire.read();
28 accelerometer_z = Wire.read() << 8 | Wire.read();
29 temperature = Wire.read() << 8 | Wire.read();
30 gyro_x = Wire.read() << 8 | Wire.read();
31 gyro_y = Wire.read() << 8 | Wire.read();
32 gyro_z = Wire.read() << 8 | Wire.read();
33 Serial.println("BOOT1");
34 if(Serial.available() > 0){
35 for(int i =0;i < Serial.available();i++){
36 buffer += Serial.read();
37 }
38 if(buffer == "X"){
39 buffer = ""
40 Serial.println(analogRead(A0));
41 }else if(buffer == "Y"){
42 buffer = ""
43 Serial.println(analogRead(A1));
44 }
45 }
46}
47