Interface for an LIS302 accelerometer, using the SPI interface
Dependents: LIS302_HelloWorld mbed_line_camera
LIS302 Class Reference
An interface for the LIS302 triple axis SPI accelerometer. More...
#include <LIS302.h>
Public Member Functions | |
LIS302 (PinName mosi, PinName miso, PinName clk, PinName ncs) | |
Create an LIS302 interface, connected to the specified pins. | |
float | x () |
Read the X axis acceleration. | |
float | y () |
Read the Y axis acceleration. | |
float | z () |
Read the Z axis acceleration. | |
void | range (int g) |
Select the range of the accelerometer. | |
void | calibrate (float maxx=1, float minx=-1, float maxy=1, float miny=-1, float maxz=1, float minz=-1) |
Configure the minima and maxima for the axes to linearise the readings. |
Detailed Description
An interface for the LIS302 triple axis SPI accelerometer.
// Print out the Z axis acceleration #include "mbed.h" #include "LIS302.h" LIS302 acc(p5, p6, p7, p8); // mosi, miso, clk, ncs int main() { while(1) { printf("Z axis acceleration = %.2f\n", acc.z()); wait(0.1); } }
Definition at line 45 of file LIS302.h.
Constructor & Destructor Documentation
LIS302 | ( | PinName | mosi, |
PinName | miso, | ||
PinName | clk, | ||
PinName | ncs | ||
) |
Create an LIS302 interface, connected to the specified pins.
- Parameters:
-
mosi SPI data out miso SPI data in clk SPI clock ncs Active low chip select (DigitalOut)
Definition at line 57 of file LIS302.cpp.
Member Function Documentation
void calibrate | ( | float | maxx = 1 , |
float | minx = -1 , |
||
float | maxy = 1 , |
||
float | miny = -1 , |
||
float | maxz = 1 , |
||
float | minz = -1 |
||
) |
Configure the minima and maxima for the axes to linearise the readings.
- Parameters:
-
maxx float defining the maximum X value minx float defining the minimum X value maxy float defining the maximum Y value miny float defining the minimum Y value maxz float defining the maximum Z value minz float defining the minimum Z value
Definition at line 151 of file LIS302.cpp.
void range | ( | int | g ) |
Select the range of the accelerometer.
- Parameters:
-
range 0 = 2g, 1 = 8g
Definition at line 128 of file LIS302.cpp.
float x | ( | ) |
Read the X axis acceleration.
- Returns:
- A floating-point value representing acceleration in g
Definition at line 89 of file LIS302.cpp.
float y | ( | ) |
Read the Y axis acceleration.
- Returns:
- A floating-point value representing acceleration in g
Definition at line 102 of file LIS302.cpp.
float z | ( | ) |
Read the Z axis acceleration.
- Returns:
- - A floating-point value representing acceleration in g
Definition at line 115 of file LIS302.cpp.
Generated on Tue Jul 12 2022 11:48:13 by 1.7.2