Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter).
Dependents: stm32f407 mbed_blinky STM32F407
LIS3DSH Class Reference
Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter). More...
#include <LIS3DSH.h>
Public Member Functions | |
LIS3DSH (PinName mosi, PinName miso, PinName clk, PinName cs) | |
Create a LIS3DSH object connected to the specified pins. | |
int | Detect (void) |
Determines if the LIS3DSH acceleromoter can be detected. | |
void | WriteReg (uint8_t addr, uint8_t data) |
Write a byte of data to the LIS3DSH at a selected address. | |
uint8_t | ReadReg (uint8_t addr) |
Read data from the LIS3DSH from a selected address. | |
void | ReadData (int16_t *X, int16_t *Y, int16_t *Z) |
Reads the raw X, Y, Z values from the LIS3DSH as signed 16-bit values (int16_t). | |
void | ReadAngles (float *Roll, float *Pitch) |
Reads the roll angle and pitch angle from the LIS3DSH. |
Detailed Description
Class library for a LIS3DSH MEMS digital output motion sensor (acceleromoter).
Example:
#include "mbed.h" #include "LIS3DSH.h" LIS3DSH acc(PA_7, PA_6, PA_5, PE_3); // mosi, miso, clk , cs int main() { int16_t X, Y, Z; //signed integer variables for raw X,Y,Z values float roll, pitch; //float variables for angles if(acc.Detect() != 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 printf("X: %d Y: %d Z: %d\n", X, Y, Z); printf("Roll: %f Pitch: %f\n", roll, pitch); wait(1.0); //delay before reading next values } }
Definition at line 61 of file LIS3DSH.h.
Constructor & Destructor Documentation
LIS3DSH | ( | PinName | mosi, |
PinName | miso, | ||
PinName | clk, | ||
PinName | cs | ||
) |
Create a LIS3DSH object connected to the specified pins.
- Parameters:
-
mosi SPI compatible pin used for the LIS3DSH's MOSI pin miso SPI compatible pin used for the LIS3DSH's MISO pin clk SPI compatible pin used for the LIS3DSH's CLK pin cs DigitalOut compatible pin used for the LIS3DSH's CS pin
Definition at line 27 of file LIS3DSH.cpp.
Member Function Documentation
int Detect | ( | void | ) |
Determines if the LIS3DSH acceleromoter can be detected.
- Parameters:
-
None
- Returns:
- 1 = detected; 0 = not detected.
Definition at line 70 of file LIS3DSH.cpp.
void ReadAngles | ( | float * | Roll, |
float * | Pitch | ||
) |
Reads the roll angle and pitch angle from the LIS3DSH.
- Parameters:
-
Roll Reference to variable for the roll angle (0.0 - 359.999999) Pitch Reference to variable for the pitch angle (0.0 - 359.999999)
- Returns:
- None
Definition at line 93 of file LIS3DSH.cpp.
void ReadData | ( | int16_t * | X, |
int16_t * | Y, | ||
int16_t * | Z | ||
) |
Reads the raw X, Y, Z values from the LIS3DSH as signed 16-bit values (int16_t).
- Parameters:
-
X Reference to variable for the raw X value Y Reference to variable for the raw Y value Z Reference to variable for the raw Z value
- Returns:
- None
Definition at line 77 of file LIS3DSH.cpp.
uint8_t ReadReg | ( | uint8_t | addr ) |
Read data from the LIS3DSH from a selected address.
- Parameters:
-
addr 8-bit address from where the data should be read
- Returns:
- Contents of the register as a 8-bit data byte.
Definition at line 59 of file LIS3DSH.cpp.
void WriteReg | ( | uint8_t | addr, |
uint8_t | data | ||
) |
Write a byte of data to the LIS3DSH at a selected address.
- Parameters:
-
addr 8-bit address to where the data should be written data 8-bit data byte to write
- Returns:
- None
Definition at line 52 of file LIS3DSH.cpp.
Generated on Tue Jul 12 2022 15:41:48 by 1.7.2