Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1993 - 1
/**************************************************************************
2
 *                                                                         *
3
 * ADXL345 Driver for Arduino                                              *
4
 *                                                                         *
5
 ***************************************************************************
6
 *                                                                         *
7
 * This program is free software; you can redistribute it and/or modify    *
8
 * it under the terms of the MIT License.                                  *
9
 * This program is distributed in the hope that it will be useful,         *
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
12
 * MIT License for more details.                                           *
13
 *                                                                         *
14
 ***************************************************************************
15
 *
16
 * Revision History
17
 *
18
 * Date  By What
19
 * 20100515 TJS Initial Creation
20
 * 20100524 TJS Modified to run with Kevin Stevenard's driver
21
 */
22
#include "Wire.h"
23
#include "ADXL345.h"
24
 
25
ADXL345 Accel;
26
 
27
void setup(){
28
  Serial.begin(9600);
29
  delay(1);
30
  Wire.begin();
31
  delay(1);
32
  Serial.println("Here");
33
  Accel.init(ADXL345_ADDR_ALT_LOW);
34
  Accel.set_bw(ADXL345_BW_12);
35
  Serial.print("BW_OK? ");
36
  Serial.println(Accel.status, DEC);
37
  delay(1000);
38
}
39
 
40
void loop(){
41
  int i;
42
  float acc_data[3];
43
  Accel.get_Gxyz(acc_data);
44
  if(Accel.status){
45
    float length = 0.;
46
    for(i = 0; i < 3; i++){
47
      length += (float)acc_data[i] * (float)acc_data[i];
48
      Serial.print(acc_data[i]);
49
      Serial.print(" ");
50
    }
51
    length = sqrt(length);
52
    Serial.print(length);
53
    Serial.println("");
54
    delay(40);
55
  }
56
  else{
57
    Serial.println("ERROR: ADXL345 data read error");
58
  }
59
}