Kazushi Mukaiyama / LS302i2c
Embed: (wiki syntax)

« Back to documentation index

LIS302i2c Class Reference

LIS302i2c Class Reference

An interface for the LIS302 triple axis I2C accelerometer. More...

#include <LIS302i2c.h>

Public Member Functions

 LIS302i2c (int addr, PinName sda, PinName scl)
 Create an LIS302 interface, connected to the specified pins.
float getX ()
 Read the X axis acceleration.
float getY ()
 Read the Y axis acceleration.
float getZ ()
 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 I2C accelerometer.

 // Print out the Z axis acceleration
 #include "mbed.h"
 #include "LIS302i2c.h"
 
 LIS302i2c acc(p28, p27); // sda, scl
 
 int main() {
     while(1) {
         printf("Z axis acceleration = %.2f\n", acc.getZ());
         wait(0.1);              
     }
 }

Definition at line 46 of file LIS302i2c.h.


Constructor & Destructor Documentation

LIS302i2c ( int  addr,
PinName  sda,
PinName  scl 
)

Create an LIS302 interface, connected to the specified pins.

Parameters:
sdaI2C data line pin
sclI2C clock line pin

Definition at line 59 of file LIS302i2c.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 163 of file LIS302i2c.cpp.

float getX (  )

Read the X axis acceleration.

Returns:
A floating-point value representing acceleration in g

Definition at line 99 of file LIS302i2c.cpp.

float getY (  )

Read the Y axis acceleration.

Returns:
A floating-point value representing acceleration in g

Definition at line 113 of file LIS302i2c.cpp.

float getZ (  )

Read the Z axis acceleration.

Returns:
- A floating-point value representing acceleration in g

Definition at line 127 of file LIS302i2c.cpp.

void range ( int  g )

Select the range of the accelerometer.

Parameters:
range0 = 2g, 1 = 8g

Definition at line 141 of file LIS302i2c.cpp.