-
Notifications
You must be signed in to change notification settings - Fork 0
/
accelerometer.ino
93 lines (76 loc) · 2.17 KB
/
accelerometer.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
#define THRESHOLD 35
#define DURATION 1
#define RESET_TILT_STATE_TIMER 1000
boolean tiltState =false;
unsigned long int lastTiltTime=0;
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void AccSetup()
{
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G))
{
delay(500);
}
mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);
mpu.setIntFreeFallEnabled(false);
mpu.setIntZeroMotionEnabled(false);
mpu.setIntMotionEnabled(false);
mpu.setDHPFMode(MPU6050_DHPF_5HZ);
mpu.setMotionDetectionThreshold(THRESHOLD);
mpu.setMotionDetectionDuration(DURATION);
//checkSettings();
}
void accLoop()
{
Vector rawAccel = mpu.readRawAccel();
Activites act = mpu.readActivites();
if (act.isActivity) setTiltState();
else if(tiltState && millis()-lastTiltTime>=RESET_TILT_STATE_TIMER) resetTiltState();
}
void setTiltState(){
// Serial.println("TILT");
//resetCapacitives();
lastTiltTime=millis();
tiltState=true;
}
void resetTiltState(){
resetCapacitives();
tiltState=false;
}
////##########################################################################################################################################################################
//void accSetup2()
//{
// while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
// {
// delay(500);
// }
//
// // If you want, you can set accelerometer offsets
// // mpu.setAccelOffsetX();
// // mpu.setAccelOffsetY();
// // mpu.setAccelOffsetZ();
//
//}
//
//void accLoop2()
//{
//// Vector rawAccel = mpu.readRawAccel();
// Vector normAccel = mpu.readNormalizeAccel();
//
//// Serial.print(" Xraw = ");
//// Serial.print(rawAccel.XAxis);
//// Serial.print(" Yraw = ");
//// Serial.print(rawAccel.YAxis);
//// Serial.print(" Zraw = ");
//// Serial.println(rawAccel.ZAxis);
//
//// Serial.print(" Xnorm = ");
//// Serial.print(normAccel.XAxis);
//// Serial.print(" Ynorm = ");
//// Serial.print(normAccel.YAxis);
//// Serial.print(" Znorm = ");
//// Serial.println(normAccel.ZAxis);
//// if (normAccel.XAxis>THRESH || normAccel.YAxis>THRESH || normAccel.ZAxis>THRESH) setTiltState();
//// else if(tiltState && millis()-lastTiltTime>=RESET_TILT_STATE_TIMER) resetTiltState();
//}