I-O DATA DEV2
/
lis3dh-3dacc
acc sensor test
main.cpp@0:61c02ea0efd9, 2020-11-04 (annotated)
- Committer:
- hakusan270
- Date:
- Wed Nov 04 03:13:18 2020 +0000
- Revision:
- 0:61c02ea0efd9
LIS3DH sample
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hakusan270 | 0:61c02ea0efd9 | 1 | #include "mbed.h" |
hakusan270 | 0:61c02ea0efd9 | 2 | #include "LIS3DH.h" |
hakusan270 | 0:61c02ea0efd9 | 3 | DigitalOut myled(LED1); |
hakusan270 | 0:61c02ea0efd9 | 4 | |
hakusan270 | 0:61c02ea0efd9 | 5 | |
hakusan270 | 0:61c02ea0efd9 | 6 | #if 0 |
hakusan270 | 0:61c02ea0efd9 | 7 | SPI STSPI(SPI_MOSI, SPI_MISO, SPI_SCK); |
hakusan270 | 0:61c02ea0efd9 | 8 | DigitalOut STSPICS(D6); |
hakusan270 | 0:61c02ea0efd9 | 9 | #endif |
hakusan270 | 0:61c02ea0efd9 | 10 | |
hakusan270 | 0:61c02ea0efd9 | 11 | I2C Acc(PB_9, PB_8); // SDA, SCL |
hakusan270 | 0:61c02ea0efd9 | 12 | #define SLAVE_ADD 0x30 //LIS3DH I2C slave address |
hakusan270 | 0:61c02ea0efd9 | 13 | LIS3DH acc(PB_9,PB_8, SLAVE_ADD ); |
hakusan270 | 0:61c02ea0efd9 | 14 | |
hakusan270 | 0:61c02ea0efd9 | 15 | |
hakusan270 | 0:61c02ea0efd9 | 16 | |
hakusan270 | 0:61c02ea0efd9 | 17 | int main() |
hakusan270 | 0:61c02ea0efd9 | 18 | { |
hakusan270 | 0:61c02ea0efd9 | 19 | int val; |
hakusan270 | 0:61c02ea0efd9 | 20 | float xyz[3]; |
hakusan270 | 0:61c02ea0efd9 | 21 | printf("Hello LIS3DH test\r\n"); |
hakusan270 | 0:61c02ea0efd9 | 22 | |
hakusan270 | 0:61c02ea0efd9 | 23 | val = acc.read_id(); |
hakusan270 | 0:61c02ea0efd9 | 24 | printf("I2c read ID %02x\r\n",val); |
hakusan270 | 0:61c02ea0efd9 | 25 | while(1) { |
hakusan270 | 0:61c02ea0efd9 | 26 | myled = !myled; |
hakusan270 | 0:61c02ea0efd9 | 27 | wait(0.5); |
hakusan270 | 0:61c02ea0efd9 | 28 | acc.data_ready(); |
hakusan270 | 0:61c02ea0efd9 | 29 | acc.read_data(xyz); |
hakusan270 | 0:61c02ea0efd9 | 30 | printf(" x=%f y=%f z=%f\r\n",xyz[0],xyz[1],xyz[2]); |
hakusan270 | 0:61c02ea0efd9 | 31 | } |
hakusan270 | 0:61c02ea0efd9 | 32 | } |