Interface for an LIS302 accelerometer, using the SPI interface

Dependents:   LIS302_HelloWorld mbed_line_camera

Embed: (wiki syntax)

« Back to documentation index

LIS302 Class Reference

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:
mosiSPI data out
misoSPI data in
clkSPI clock
ncsActive 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:
maxxfloat defining the maximum X value
minxfloat defining the minimum X value
maxyfloat defining the maximum Y value
minyfloat defining the minimum Y value
maxzfloat defining the maximum Z value
minzfloat defining the minimum Z value

Definition at line 151 of file LIS302.cpp.

void range ( int  g )

Select the range of the accelerometer.

Parameters:
range0 = 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.