Recent changes
Slingshot user guide
tag Guide, user
NFCLamp user guide
tag Guide, user
Homepage
MPL115A2
Compiler Error 42
From the mbed microcontroller Cookbook.  

LIS302 Accelerometer

An LIS302 is a 3-axis accelerometer, accessible via a digital SPI interface with a selectable range of 2g or 8g.

LIS302 Breakout

Hello World!

» Import this program

00001 // LIS302 Hello World! moves leds based on x acceleration
00002 
00003 #include "mbed.h"
00004 #include "LIS302.h"
00005 
00006 LIS302 acc(p5, p6, p7, p8); // mosi, miso, sclk, ncs
00007 BusOut leds(LED1, LED2, LED3, LED4);
00008 
00009 int main() {
00010     while(1) {
00011         leds = 1 << (int)(4 * acc.x());
00012         wait(0.1);
00013     }
00014 }
LIS302 Signal Namembed pin
VccVout
GndGnd
SCLp7
MOSIp5
MISOp6
CSp8

Hello World Wiring

Library

» Import this library into a program

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.

Reference




calendar Page history
Last modified 23 Nov 2010, by   user Simon Ford   tag LIS302, SPI | 0 comments  

Please login to post comments.