I-O DATA DEV2
/
lis3dh-3dacc
acc sensor test
main.cpp
- Committer:
- hakusan270
- Date:
- 2020-11-04
- Revision:
- 0:61c02ea0efd9
File content as of revision 0:61c02ea0efd9:
#include "mbed.h" #include "LIS3DH.h" DigitalOut myled(LED1); #if 0 SPI STSPI(SPI_MOSI, SPI_MISO, SPI_SCK); DigitalOut STSPICS(D6); #endif I2C Acc(PB_9, PB_8); // SDA, SCL #define SLAVE_ADD 0x30 //LIS3DH I2C slave address LIS3DH acc(PB_9,PB_8, SLAVE_ADD ); int main() { int val; float xyz[3]; printf("Hello LIS3DH test\r\n"); val = acc.read_id(); printf("I2c read ID %02x\r\n",val); while(1) { myled = !myled; wait(0.5); acc.data_ready(); acc.read_data(xyz); printf(" x=%f y=%f z=%f\r\n",xyz[0],xyz[1],xyz[2]); } }