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.
Dependents: LowpassFilter_test
LIS3DH.cpp
00001 #include "LIS3DH.h" 00002 00003 LIS3DH::LIS3DH( PinName sda, PinName scl ) : i2c(sda, scl ) 00004 { 00005 } 00006 00007 00008 int LIS3DH::start(void) 00009 { 00010 addr = WRITE_ADDR; 00011 dbf[0] = LIS3DH_WHO_AM_I; 00012 i2c.write(addr, dbf,1); 00013 i2c.read(addr | 1, dbf, 1); 00014 if (dbf[0] == I_AM_LIS3DH) { 00015 return 1; 00016 } 00017 else { 00018 return 0; 00019 } 00020 } 00021 00022 void LIS3DH::read_data(float a[]) 00023 { 00024 char data[6]; 00025 dbf[0] = LIS3DH_CTRL_REG1; 00026 dbf[1] = 0x7f; 00027 i2c.write(addr , dbf , 2); 00028 dbf[0] = LIS3DH_OUT_X_L | 0x80; 00029 i2c.write(addr, dbf, 1); 00030 i2c.read(addr | 1, data, 6); 00031 a[0] = float(short((data[1]<<8) | data[0])) *LIS3DH_SENSITIVITY_2G / 15; 00032 a[1] = float(short((data[3]<<8) | data[2])) *LIS3DH_SENSITIVITY_2G / 15; 00033 a[2] = float(short((data[5]<<8) | data[4])) *LIS3DH_SENSITIVITY_2G / 15; 00034 }
Generated on Tue Jul 12 2022 22:25:34 by
1.7.2