Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1993 - 1
#include "Wire.h"
2
#include "ADXL345.h"
3
 
4
ADXL345 accel;
5
 
6
void setup(void){
7
  int x, y, z, i;
8
  double xyz[3], gains[3], gains_orig[3];
9
 
10
  Serial.begin(9600);
11
  accel.init(ADXL345_ADDR_ALT_LOW);
12
  accel.powerOn();
13
  Serial.println("Arduino driver for ADXL345 3-axes accelerometer");
14
  Serial.println("Version 2.0");
15
  Serial.println("");
16
  Serial.println("This program is free software; you can redistribute it and/or modify");
17
  Serial.println("it under the terms of the GNU License V2.");
18
  Serial.println("This program is distributed in the hope that it will be useful,");
19
  Serial.println("but WITHOUT ANY WARRANTY; without even the implied warranty of");
20
  Serial.println("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ");
21
  Serial.println("GNU General Public License, version 2 for more details");
22
 
23
  Serial.println("");
24
  Serial.println("Original development: Kevin Stevenard");
25
  Serial.println("Modified by Justin Shaw May 2010");
26
  Serial.println("");
27
  Serial.println("");
28
 
29
  accel.getAxisGains(gains_orig);
30
  Serial.println("gains_orig[]:");
31
  for(i = 0; i < 3; i++){
32
    Serial.print(gains_orig[i], 6);
33
    Serial.print(" ");
34
  }
35
  Serial.println("");
36
 
37
  gains[0] = .1;
38
  gains[1] = 1.1;
39
  gains[2] = 2.1;
40
  accel.setAxisGains(gains);
41
  accel.getAxisGains(gains);
42
  Serial.println("set gains[]:");
43
  for(i = 0; i < 3; i++){
44
    Serial.print(gains[i]);
45
    Serial.print(" ");
46
  }
47
  Serial.println("");
48
 
49
  accel.setAxisGains(gains_orig);
50
  accel.getAxisGains(gains);
51
  Serial.println("original gains?");
52
  for(i = 0; i < 3; i++){
53
    Serial.print(gains[i], 6);
54
    Serial.print(" ");
55
  }
56
  Serial.println("");
57
 
58
  accel.readAccel(&x, &y, &z);
59
  Serial.print("XYZ COUNTS: ");
60
  Serial.print(x, DEC);
61
  Serial.print(" ");
62
  Serial.print(y, DEC);
63
  Serial.print(" ");
64
  Serial.print(z, DEC);
65
  Serial.println("");
66
 
67
  accel.get_Gxyz(xyz);
68
  Serial.print("XYZ Gs: ");
69
  for(i = 0; i<3; i++){
70
    Serial.print(xyz[i], DEC);
71
    Serial.print(" ");
72
  }
73
  Serial.println("");
74
 
75
  accel.setTapThreshold(1);
76
  Serial.print("getTapThreshold(): ");
77
  Serial.println(accel.getTapThreshold(), DEC);
78
 
79
  accel.setAxisOffset(2, 3, 4);
80
  Serial.print("getAxisOffset(&x, &y, &z): ");
81
  accel.getAxisOffset(&x, &y, &z);
82
  Serial.print(x);
83
  Serial.print(" ");
84
  Serial.print(y);
85
  Serial.print(" ");
86
  Serial.print(z);
87
  Serial.println("");
88
 
89
  accel.setTapDuration(5);
90
  Serial.print("getTapDuration(): ");
91
  Serial.println(accel.getTapDuration(), DEC);
92
 
93
  accel.setDoubleTapLatency(6);
94
  Serial.print("getDoubleTapLatency(): ");
95
  Serial.println(accel.getDoubleTapLatency(), DEC);
96
 
97
  accel.setDoubleTapWindow(7);
98
  Serial.print("getDoubleTapWindow() ");
99
  Serial.println(accel.getDoubleTapWindow());
100
 
101
  accel.setActivityThreshold(8);
102
  Serial.print("getActivityThreshold() ");
103
  Serial.println(accel.getActivityThreshold(), DEC);
104
 
105
  accel.setInactivityThreshold(9);
106
  Serial.print("getInactivityThreshold() ");
107
  Serial.println(accel.getInactivityThreshold(), DEC);
108
 
109
  accel.setTimeInactivity(10);
110
  Serial.print("getTimeInactivity(): ");
111
  Serial.println(accel.getTimeInactivity());
112
 
113
  accel.setFreeFallThreshold(11);
114
  Serial.print("getFreeFallThreshold(): ");
115
  Serial.println(accel.getFreeFallThreshold());
116
 
117
  accel.setFreeFallDuration(12);
118
  Serial.print("getFreeFallDuration(): ");
119
  Serial.println(accel.getFreeFallDuration(), DEC);
120
 
121
  Serial.print("isActivityXEnabled(): ");
122
  Serial.println(accel.isActivityXEnabled(), DEC);
123
 
124
  Serial.print("isActivityYEnabled(): ");
125
  Serial.println(accel.isActivityYEnabled(), DEC);
126
 
127
  Serial.print("isActivityZEnabled(): ");
128
  Serial.println(accel.isActivityZEnabled(), DEC);
129
 
130
  Serial.print("isInactivityXEnabled(): ");
131
  Serial.println(accel.isInactivityXEnabled(), DEC);
132
 
133
  Serial.print("isInactivityYEnabled(): ");
134
  Serial.println(accel.isInactivityYEnabled(), DEC);
135
 
136
  Serial.print("isInactivityZEnabled(): ");
137
  Serial.println(accel.isInactivityZEnabled(), DEC);
138
 
139
  Serial.print("isActivityAc(): ");
140
  Serial.println(accel.isInactivityAc(), DEC);
141
 
142
  accel.setActivityAc(true);
143
  accel.setInactivityAc(true);
144
 
145
  accel.setSuppressBit(true);
146
  Serial.print("getSuppressBit(); true? ");
147
  Serial.println(accel.getSuppressBit());
148
 
149
  accel.setSuppressBit(false);
150
  Serial.print("getSuppressBit(); false? ");
151
  Serial.println(accel.getSuppressBit());
152
 
153
  accel.setTapDetectionOnX(true);
154
  Serial.print("isTapDetectionOnX(); true? ");
155
  Serial.println(accel.isTapDetectionOnX(), DEC);
156
  accel.setTapDetectionOnX(false);
157
  Serial.print("isTapDetectionOnX(); false? ");
158
  Serial.println(accel.isTapDetectionOnX(), DEC);
159
 
160
  accel.setTapDetectionOnY(true);
161
  Serial.print("isTapDetectionOnY(); true? ");
162
  Serial.println(accel.isTapDetectionOnY(), DEC);
163
  accel.setTapDetectionOnY(false);
164
  Serial.print("isTapDetectionOnY(); false? ");
165
  Serial.println(accel.isTapDetectionOnY(), DEC);
166
 
167
  accel.setTapDetectionOnZ(true);
168
  Serial.print("isTapDetectionOnZ(); true? ");
169
  Serial.println(accel.isTapDetectionOnZ(), DEC);
170
  accel.setTapDetectionOnZ(false);
171
  Serial.print("isTapDetectionOnZ(); false? ");
172
  Serial.println(accel.isTapDetectionOnZ(), DEC);
173
 
174
  accel.setActivityX(true);
175
  accel.setActivityY(true);
176
  accel.setActivityZ(true);
177
 
178
  accel.setInactivityX(false);
179
  accel.setInactivityY(false);
180
  accel.setInactivityZ(false);
181
 
182
  Serial.print("isActivitySourceOnX(): ");
183
  Serial.println(accel.isActivitySourceOnX(), DEC);
184
 
185
  Serial.print("accel.isActivitySourceOnY(): ");
186
  Serial.println(accel.isActivitySourceOnY(), DEC);
187
 
188
  Serial.print("accel.isActivitySourceOnZ(): ");
189
  Serial.println(accel.isActivitySourceOnZ(), DEC);
190
 
191
  Serial.print("accel.isTapSourceOnX(): ");
192
  Serial.println(accel.isTapSourceOnX(), DEC);
193
 
194
  Serial.print("accel.isTapSourceOnY(): ");
195
  Serial.println(accel.isTapSourceOnY(), DEC);
196
 
197
  Serial.print("accel.isTapSourceOnZ(): ");
198
  Serial.println(accel.isTapSourceOnZ(), DEC);
199
 
200
  Serial.print("accel.isAsleep(): ");
201
  Serial.println(accel.isAsleep(), DEC);
202
 
203
  Serial.print("accel.isLowPower(): ");
204
  Serial.println(accel.isLowPower(), DEC);
205
 
206
  accel.setLowPower(false);
207
 
208
  accel.setRate(3.14159);
209
  Serial.print("getRate(): 3.14159?");
210
  Serial.println(accel.getRate());
211
 
212
  Serial.print("getInterruptSource(): ");
213
  Serial.println(accel.getInterruptSource(), DEC);
214
 
215
  Serial.print("getInterruptSource(1): ");
216
  Serial.println(accel.getInterruptSource(1), DEC);
217
 
218
  Serial.print("getInterruptMapping(1): ");
219
  Serial.println(accel.getInterruptMapping(1), DEC);
220
 
221
  accel.setInterruptMapping(1, true);
222
  Serial.print("isInterruptEnabled(1): ");
223
  Serial.println(accel.isInterruptEnabled(1));
224
 
225
  accel.setInterrupt(1, true);
226
 
227
  accel.setSelfTestBit(false);
228
  Serial.print("getSelfTestBit(): ");
229
  Serial.println(accel.getSelfTestBit(), DEC);
230
 
231
  accel.printAllRegister();
232
}
233
void loop(void){
234
}