初めてのライブラリなので中身は....
Dependents: LowpassFilter_test
LIS3DH.h
00001 #ifndef LIS3DH_H 00002 #define LIS3DH_H 00003 00004 #include "mbed.h" 00005 00006 // addr 00007 #define WRITE_ADDR 0x30 00008 #define READ_ADDR 0x31 00009 // LIS3DH ID 00010 #define I_AM_LIS3DH 0x33 00011 00012 // Register's definition 00013 #define LIS3DH_STATUS_REG_AUX 0x07 00014 #define LIS3DH_OUT_ADC1_L 0x08 00015 #define LIS3DH_OUT_ADC1_H 0x09 00016 #define LIS3DH_OUT_ADC2_L 0x0a 00017 #define LIS3DH_OUT_ADC2_H 0x0b 00018 #define LIS3DH_OUT_ADC3_L 0x0c 00019 #define LIS3DH_OUT_ADC3_H 0x0d 00020 #define LIS3DH_INT_COUNTER_REG 0x0e 00021 #define LIS3DH_WHO_AM_I 0x0f 00022 #define LIS3DH_TEMP_CFG_REG 0x1f 00023 #define LIS3DH_CTRL_REG1 0x20 00024 #define LIS3DH_CTRL_REG2 0x21 00025 #define LIS3DH_CTRL_REG3 0x22 00026 #define LIS3DH_CTRL_REG4 0x23 00027 #define LIS3DH_CTRL_REG5 0x24 00028 #define LIS3DH_CTRL_REG6 0x25 00029 #define LIS3DH_REFERENCE 0x26 00030 #define LIS3DH_STATUS_REG2 0x27 00031 #define LIS3DH_OUT_X_L 0x28 00032 #define LIS3DH_OUT_X_H 0x29 00033 #define LIS3DH_OUT_Y_L 0x2a 00034 #define LIS3DH_OUT_Y_H 0x2b 00035 #define LIS3DH_OUT_Z_L 0x2c 00036 #define LIS3DH_OUT_Z_H 0x2d 00037 #define LIS3DH_FIFO_CTRL_REG 0x2e 00038 #define LIS3DH_FIFO_SRC_REG 0x2f 00039 #define LIS3DH_INT1_CFG 0x30 00040 #define LIS3DH_INT1_SOURCE 0x31 00041 #define LIS3DH_INT1_THS 0x32 00042 #define LIS3DH_INT1_DURATION 0x33 00043 #define LIS3DH_CLICK_CFG 0x38 00044 #define LIS3DH_CLICK_SRC 0x39 00045 #define LIS3DH_CLICK_THS 0x3a 00046 #define LIS3DH_TIME_LIMIT 0x3b 00047 #define LIS3DH_TIME_LATENCY 0x3c 00048 #define LIS3DH_TIME_WINDOW 0x3d 00049 00050 // definition for Nomalization 00051 #define LIS3DH_SENSITIVITY_2G (0.001F) 00052 #define LIS3DH_SENSITIVITY_4G (0.002F) 00053 #define LIS3DH_SENSITIVITY_8G (0.004F) 00054 #define LIS3DH_SENSITIVITY_16G (0.012F) 00055 /** Create a LIS3DH instance connected to specified I2C pins with specified address 00056 * 00057 * @param sda I2C-bus SDA pin 00058 * @param scl I2C-bus SCL pin 00059 */ 00060 class LIS3DH 00061 { 00062 public: 00063 LIS3DH(PinName sda, PinName scl ); 00064 int start(void); 00065 void read_data(float a[]); 00066 private: 00067 I2C i2c; 00068 char dbf[2],addr; 00069 }; 00070 #endif //LIS3DH 00071 /*sample main.cpp code 00072 00073 #include "mbed.h" 00074 #include "LIS3DH.h" 00075 00076 LIS3DH I2c(p9,p10); //sda,scl 00077 Serial pc(USBTX,USBRX); 00078 int main(){ 00079 int check; 00080 check = I2c.start(); 00081 if (check == 1) { 00082 while(1) { 00083 float dt[2]; 00084 I2c.read_data(dt); 00085 pc.printf("X=%f __Y=%f __Z=%f \n",dt[0],dt[1],dt[2]); 00086 wait(1); 00087 } 00088 } 00089 } 00090 */
Generated on Tue Jul 12 2022 22:25:34 by
1.7.2