Simon Ford / Mbed 2 deprecated LIS302Dev

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LIS302.h Source File

LIS302.h

00001 /* mbed LIS302 Accelerometer
00002  * Copyright (c) 2008-2009 cstyles, wreynolds, sford
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005 
00006 #ifndef MBED_LIS302_H
00007 #define MBED_LIS302_H
00008  
00009 #include "mbed.h"
00010 
00011 /* Class: LIS302
00012  *  An abstraction for the LIS302 triple axis SPI accelerometer
00013  *
00014  * Example:
00015  * > // Print out the Z axis acceleration
00016  * >
00017  * > #include "mbed.h"
00018  * > #include "LIS302.h"
00019  * >
00020  * > LIS302 acc(p5, p6, p7, p8); // mosi, miso, clk, ncs
00021  * >
00022  * > int main() {
00023  * >     while(1) {
00024  * >         printf("Z axis acceleration = %.2f\n", acc.z());
00025  * >         wait(0.1);              
00026  * >     }
00027  * > }
00028  */
00029 class LIS302  {
00030 public:
00031 
00032     /* Constructor: LIS302
00033      *  Create an object for the LIS302, connected to the specified pins
00034      *
00035      * Variables:
00036      *  mosi - SPI data out
00037      *  miso - SPI data in
00038      *  clk - SPI clock
00039      *  ncs - Active low chip select. Any DigitalOut will do
00040      */
00041     LIS302(PinName mosi, PinName miso, PinName clk, PinName ncs);
00042 
00043     /* Function: x
00044      *  Read the X axis acceleration
00045      *
00046      * Variables:
00047      *  returns - A floating-point value representing acceleration in g
00048      */    
00049     float x();
00050 
00051     /* Function: y
00052      *  Read the Y axis acceleration
00053      *
00054      * Variables:
00055      *  returns - A floating-point value representing acceleration in g
00056      */    
00057     float y();
00058 
00059     /* Function: z
00060      *  Read the Z axis acceleration
00061      *
00062      * Variables:
00063      *  returns - A floating-point value representing acceleration in g
00064      */    
00065     float z();
00066 
00067     /* Function: range
00068      *  Select the range of the accelerometer
00069      *
00070      * Variables:
00071      *  range - 0 = 2g, 1 = 8g
00072      */        
00073     void range(int g);
00074 
00075     /* Function: Calibrate
00076      *  Configure the minima and maxima for the axes to linearise the readings
00077      *
00078      * Variables:
00079      *  maxx - float defining the maximum X value
00080      *  minx - float defining the minimum X value
00081      *  maxy - float defining the maximum Y value
00082      *  miny - float defining the minimum Y value
00083      *  maxz - float defining the maximum Z value
00084      *  minz - float defining the minimum Z value
00085      */        
00086     void calibrate(float maxx = 1, float minx = -1, float maxy = 1, float miny = -1, float maxz = 1, float minz = -1);
00087     
00088 private:
00089     SPI _spi;
00090     DigitalOut _ncs;    
00091 
00092     int whoami();
00093     int status();
00094     
00095     float _factor;
00096     float _maxx, _minx;
00097     float _maxy, _miny;
00098     float _maxz, _minz;        
00099 };
00100 
00101 #endif