/*############################################################# Program Name : ex1_LIS3DSH Author : Grant Phillips Date Modified : 09/08/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Example program that demonstrates the use of an LIS3DSH MEMS digital output motion sensor (acceleromoter). The output is displayed on a PC using the Serial Wire Viewer (SWV). See the SWV examples for an explanation of the use of this feature. Requirements : * STM32F4-Discovery Board Circuit : * The LIS3DSH acceleromoter which is already on-board of the STM32F4-Discovery. The connections for the STM32F4-Discovery are fixed, but if the acceleromoter is used externally on other STM32 devices, the pins can be configured through the object. * A wire link between PB3 and pin6 of the SWD connector (CN2) as explained in the SWV examples section ##############################################################*/ #include "mbed.h" #include "LIS3DSH.h" #include "SWO.h" LIS3DSH acc(PA_7, PA_6, PA_5, PE_3); //Create a LIS3DSH object using the specified pins // mosi, miso, clk , cs SWO_Channel SWO; int main() { int rply; int16_t X, Y, Z; //signed integer variables for raw X,Y,Z values float roll, pitch; //float variables for angles rply = acc.Detect(); //check if the LIS3DSH can be detected and is functional if(rply != 1) { printf("LIS3DSH Acceleromoter not detected!\n"); while(1); } while(1) { acc.ReadData(&X, &Y, &Z); //read X, Y, Z values acc.ReadAngles(&roll, &pitch); //read roll and pitch angles SWO.printf("X: %d Y: %d Z: %d\n", X, Y, Z); SWO.printf("Roll: %f Pitch: %f\n", roll, pitch); wait(1.0); //delay before reading next values } }