Matthias Grob
/
FlyBed2
My fully self designed first stable working Quadrocopter Software.
Embed:
(wiki syntax)
Show/hide line numbers
ADXL345.h
00001 // based on http://mbed.org/users/Digixx/code/ADXL345/ 00002 00003 #ifndef ADXL345_H 00004 #define ADXL345_H 00005 00006 #include "mbed.h" 00007 #include "I2C_Sensor.h" 00008 00009 #define ADXL345_I2C_ADDRESS 0xA6 00010 //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D 00011 //when ALT ADDRESS pin is high: 00012 //#define ADXL345_I2C_ADDRESS 0x3A 00013 00014 // register addresses 00015 #define ADXL345_DEVID_REG 0x00 00016 #define ADXL345_THRESH_TAP_REG 0x1D 00017 #define ADXL345_OFSX_REG 0x1E 00018 #define ADXL345_OFSY_REG 0x1F 00019 #define ADXL345_OFSZ_REG 0x20 00020 #define ADXL345_DUR_REG 0x21 00021 #define ADXL345_LATENT_REG 0x22 00022 #define ADXL345_WINDOW_REG 0x23 00023 #define ADXL345_THRESH_ACT_REG 0x24 00024 #define ADXL345_THRESH_INACT_REG 0x25 00025 #define ADXL345_TIME_INACT_REG 0x26 00026 #define ADXL345_ACT_INACT_CTL_REG 0x27 00027 #define ADXL345_THRESH_FF_REG 0x28 00028 #define ADXL345_TIME_FF_REG 0x29 00029 #define ADXL345_TAP_AXES_REG 0x2A 00030 #define ADXL345_ACT_TAP_STATUS_REG 0x2B 00031 #define ADXL345_BW_RATE_REG 0x2C 00032 #define ADXL345_POWER_CTL_REG 0x2D 00033 #define ADXL345_INT_ENABLE_REG 0x2E 00034 #define ADXL345_INT_MAP_REG 0x2F 00035 #define ADXL345_INT_SOURCE_REG 0x30 00036 #define ADXL345_DATA_FORMAT_REG 0x31 00037 #define ADXL345_DATAX0_REG 0x32 00038 #define ADXL345_DATAX1_REG 0x33 00039 #define ADXL345_DATAY0_REG 0x34 00040 #define ADXL345_DATAY1_REG 0x35 00041 #define ADXL345_DATAZ0_REG 0x36 00042 #define ADXL345_DATAZ1_REG 0x37 00043 #define ADXL345_FIFO_CTL 0x38 00044 #define ADXL345_FIFO_STATUS 0x39 00045 00046 #define ADXL345_X 0x00 00047 #define ADXL345_Y 0x01 00048 #define ADXL345_Z 0x02 00049 00050 typedef char byte; 00051 00052 class ADXL345 : public I2C_Sensor 00053 { 00054 public: 00055 ADXL345(PinName sda, PinName scl); // constructor, uses I2C_Sensor class 00056 void read(); // read all axis to array 00057 00058 float offset[3]; // offset that's subtracted from every measurement 00059 void calibrate(int times, float separation_time); // calibration from 'times' measurements with 'separation_time' time between (get an offset while not moving) 00060 00061 private: 00062 void readraw(); 00063 }; 00064 00065 #endif
Generated on Thu Jul 14 2022 18:09:09 by 1.7.2