-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhw3bis.ino
52 lines (38 loc) · 1.2 KB
/
hw3bis.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
/* Graph I2C Accelerometer On RedBear Duo over Serial Port
* Adafruit Part 2809 LIS3DH - http://adafru.it/2809
* This example shows how to program I2C manually
* I2C Pins SDA1==D0, SCL1 == D1
* Default address: 0x18
*/
// do not use the cloud functions - assume programming through Arduino IDE
#if defined(ARDUINO)
SYSTEM_MODE(MANUAL);
#endif
#include "Adafruit_LIS3DH.h"
#include "Adafruit_Sensor.h"
// I2C
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
void setup(void) {
Serial.begin(9600);
Serial.println("LIS3DH test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1)
Serial.println("Couldn't start");
delay(1000);
}
Serial.println("LIS3DH found!");
lis.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
}
void loop() {
lis.read(); // get X Y and Z data at once
sensors_event_t event;
lis.getEvent(&event);
//send through serial transmission the values of the accelerations along the x and y axes in the form "x(xvalue)y(yvalue)"
Serial.print("x");
Serial.print(event.orientation.x);
Serial.print("y");
Serial.print(event.orientation.y);
Serial.println("");
delay(20);
}