Simon Ford / Mbed 2 deprecated LIS302Dev

Dependencies:   mbed

Committer:
simon
Date:
Fri Nov 13 11:58:12 2009 +0000
Revision:
0:c036efff0b10

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:c036efff0b10 1 /* mbed LIS302 Accelerometer
simon 0:c036efff0b10 2 * Copyright (c) 2008-2009 cstyles, wreynolds, sford
simon 0:c036efff0b10 3 * Released under the MIT License: http://mbed.org/license/mit
simon 0:c036efff0b10 4 */
simon 0:c036efff0b10 5
simon 0:c036efff0b10 6 #ifndef MBED_LIS302_H
simon 0:c036efff0b10 7 #define MBED_LIS302_H
simon 0:c036efff0b10 8
simon 0:c036efff0b10 9 #include "mbed.h"
simon 0:c036efff0b10 10
simon 0:c036efff0b10 11 /* Class: LIS302
simon 0:c036efff0b10 12 * An abstraction for the LIS302 triple axis SPI accelerometer
simon 0:c036efff0b10 13 *
simon 0:c036efff0b10 14 * Example:
simon 0:c036efff0b10 15 * > // Print out the Z axis acceleration
simon 0:c036efff0b10 16 * >
simon 0:c036efff0b10 17 * > #include "mbed.h"
simon 0:c036efff0b10 18 * > #include "LIS302.h"
simon 0:c036efff0b10 19 * >
simon 0:c036efff0b10 20 * > LIS302 acc(p5, p6, p7, p8); // mosi, miso, clk, ncs
simon 0:c036efff0b10 21 * >
simon 0:c036efff0b10 22 * > int main() {
simon 0:c036efff0b10 23 * > while(1) {
simon 0:c036efff0b10 24 * > printf("Z axis acceleration = %.2f\n", acc.z());
simon 0:c036efff0b10 25 * > wait(0.1);
simon 0:c036efff0b10 26 * > }
simon 0:c036efff0b10 27 * > }
simon 0:c036efff0b10 28 */
simon 0:c036efff0b10 29 class LIS302 {
simon 0:c036efff0b10 30 public:
simon 0:c036efff0b10 31
simon 0:c036efff0b10 32 /* Constructor: LIS302
simon 0:c036efff0b10 33 * Create an object for the LIS302, connected to the specified pins
simon 0:c036efff0b10 34 *
simon 0:c036efff0b10 35 * Variables:
simon 0:c036efff0b10 36 * mosi - SPI data out
simon 0:c036efff0b10 37 * miso - SPI data in
simon 0:c036efff0b10 38 * clk - SPI clock
simon 0:c036efff0b10 39 * ncs - Active low chip select. Any DigitalOut will do
simon 0:c036efff0b10 40 */
simon 0:c036efff0b10 41 LIS302(PinName mosi, PinName miso, PinName clk, PinName ncs);
simon 0:c036efff0b10 42
simon 0:c036efff0b10 43 /* Function: x
simon 0:c036efff0b10 44 * Read the X axis acceleration
simon 0:c036efff0b10 45 *
simon 0:c036efff0b10 46 * Variables:
simon 0:c036efff0b10 47 * returns - A floating-point value representing acceleration in g
simon 0:c036efff0b10 48 */
simon 0:c036efff0b10 49 float x();
simon 0:c036efff0b10 50
simon 0:c036efff0b10 51 /* Function: y
simon 0:c036efff0b10 52 * Read the Y axis acceleration
simon 0:c036efff0b10 53 *
simon 0:c036efff0b10 54 * Variables:
simon 0:c036efff0b10 55 * returns - A floating-point value representing acceleration in g
simon 0:c036efff0b10 56 */
simon 0:c036efff0b10 57 float y();
simon 0:c036efff0b10 58
simon 0:c036efff0b10 59 /* Function: z
simon 0:c036efff0b10 60 * Read the Z axis acceleration
simon 0:c036efff0b10 61 *
simon 0:c036efff0b10 62 * Variables:
simon 0:c036efff0b10 63 * returns - A floating-point value representing acceleration in g
simon 0:c036efff0b10 64 */
simon 0:c036efff0b10 65 float z();
simon 0:c036efff0b10 66
simon 0:c036efff0b10 67 /* Function: range
simon 0:c036efff0b10 68 * Select the range of the accelerometer
simon 0:c036efff0b10 69 *
simon 0:c036efff0b10 70 * Variables:
simon 0:c036efff0b10 71 * range - 0 = 2g, 1 = 8g
simon 0:c036efff0b10 72 */
simon 0:c036efff0b10 73 void range(int g);
simon 0:c036efff0b10 74
simon 0:c036efff0b10 75 /* Function: Calibrate
simon 0:c036efff0b10 76 * Configure the minima and maxima for the axes to linearise the readings
simon 0:c036efff0b10 77 *
simon 0:c036efff0b10 78 * Variables:
simon 0:c036efff0b10 79 * maxx - float defining the maximum X value
simon 0:c036efff0b10 80 * minx - float defining the minimum X value
simon 0:c036efff0b10 81 * maxy - float defining the maximum Y value
simon 0:c036efff0b10 82 * miny - float defining the minimum Y value
simon 0:c036efff0b10 83 * maxz - float defining the maximum Z value
simon 0:c036efff0b10 84 * minz - float defining the minimum Z value
simon 0:c036efff0b10 85 */
simon 0:c036efff0b10 86 void calibrate(float maxx = 1, float minx = -1, float maxy = 1, float miny = -1, float maxz = 1, float minz = -1);
simon 0:c036efff0b10 87
simon 0:c036efff0b10 88 private:
simon 0:c036efff0b10 89 SPI _spi;
simon 0:c036efff0b10 90 DigitalOut _ncs;
simon 0:c036efff0b10 91
simon 0:c036efff0b10 92 int whoami();
simon 0:c036efff0b10 93 int status();
simon 0:c036efff0b10 94
simon 0:c036efff0b10 95 float _factor;
simon 0:c036efff0b10 96 float _maxx, _minx;
simon 0:c036efff0b10 97 float _maxy, _miny;
simon 0:c036efff0b10 98 float _maxz, _minz;
simon 0:c036efff0b10 99 };
simon 0:c036efff0b10 100
simon 0:c036efff0b10 101 #endif