LIS302 Accelerometer
An LIS302 is a 3-axis accelerometer, accessible via a digital SPI interface with a selectable range of 2g or 8g.
 
Hello World!¶
Import 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 Name | mbed pin | 
|---|---|
| Vcc | Vout | 
| Gnd | Gnd | 
| SCL | p7 | 
| MOSI | p5 | 
| MISO | p6 | 
| CS | p8 | 
 
Library¶
Import library
    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.
    
    
     | 
  |