Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PQADXL375.h
00001 #ifndef PQADXL375_H 00002 #define PQADXL375_H 00003 00004 #define ADXL375_ADDR_HIGH 0b0011101<<1 00005 #define ADXL375_ADDR_LOW 0b1010011<<1 00006 00007 #define ADXL375_DEVID 0x00 00008 #define ADXL375_BW_RATE 0x2C 00009 #define ADXL375_POWER_CTL 0x2D 00010 #define ADXL375_DATAX0 0x32 00011 #define ADXL375_LSB 0.049 00012 00013 /** 00014 * 3軸高加速度センサADXL375のライブラリ 00015 * @code 00016 #include "mbed.h" 00017 #include "PQADXL375.h" 00018 00019 Serial pc(USBTX, USBRX, 115200); 00020 I2C i2c(p9, p10); 00021 00022 ADXL375 adxl(i2c, ADXL375::ALT_ADDRESS_HIGH); 00023 00024 float high_accel_offset[] = {0, 0, 0}; 00025 float high_accel[3]; 00026 00027 int main() { 00028 adxl.begin(); 00029 adxl.offset(high_accel); 00030 if(adxl.test()){ 00031 adxl.read(high_accel); 00032 pc.printf("%f\t%f\t%f\r\n", high_accel[0], high_accel[1], high_accel[2]); 00033 } 00034 else{ 00035 pc.printf("[ FAIL ] ADXL375 cannot be reached.\r\n"); 00036 } 00037 } 00038 * @endcode 00039 */ 00040 class ADXL375 00041 { 00042 public: 00043 typedef enum { 00044 ALT_ADDRESS_HIGH = ADXL375_ADDR_HIGH, 00045 ALT_ADDRESS_LOW = ADXL375_ADDR_LOW 00046 } ALT_ADDRESS_t; 00047 00048 private: 00049 I2C *_i2c; 00050 int _addr; 00051 char cmd[2]; 00052 char buff[6]; 00053 float high_accel_offset[3]; 00054 00055 public: 00056 /** 00057 * @param i2c I2Cのインスタンスへの参照 00058 * @param ALT_ADDRESS_t ALT_ADDRESSピンのH/Lレベル 00059 */ 00060 ADXL375 (I2C &i2c, ALT_ADDRESS_t ALT_ADDRESS); 00061 00062 /** 00063 * センサ動作開始 00064 */ 00065 void begin(); 00066 00067 /** 00068 * センサ通信テスト 00069 * @retval true 通信成功 00070 * @retval false 通信失敗 00071 */ 00072 bool test(); 00073 00074 /** 00075 * ゼロ点補正 00076 * @param high_accel 高加速度のオフセット配列 00077 */ 00078 void offset(float *high_accel); 00079 00080 /** 00081 * 測定値の読み取り 00082 * @param high_accel 高加速度を格納する配列 00083 */ 00084 void read(float *high_accel); 00085 }; 00086 00087 #endif
Generated on Sun Jul 17 2022 10:35:44 by
1.7.2