Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array

Dependencies:   USBDevice mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Wed Jul 23 17:53:28 2014 +0000
Revision:
3:3514575d4f86
Parent:
1:d913e0afb2ac
Child:
5:a70c0bce770d
Conversion to interrupt-based sampling of the accelerometer working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 1:d913e0afb2ac 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mjr 1:d913e0afb2ac 2 *
mjr 1:d913e0afb2ac 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mjr 1:d913e0afb2ac 4 * and associated documentation files (the "Software"), to deal in the Software without
mjr 1:d913e0afb2ac 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mjr 1:d913e0afb2ac 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mjr 1:d913e0afb2ac 7 * Software is furnished to do so, subject to the following conditions:
mjr 1:d913e0afb2ac 8 *
mjr 1:d913e0afb2ac 9 * The above copyright notice and this permission notice shall be included in all copies or
mjr 1:d913e0afb2ac 10 * substantial portions of the Software.
mjr 1:d913e0afb2ac 11 *
mjr 1:d913e0afb2ac 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mjr 1:d913e0afb2ac 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mjr 1:d913e0afb2ac 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mjr 1:d913e0afb2ac 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mjr 1:d913e0afb2ac 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mjr 1:d913e0afb2ac 17 */
mjr 1:d913e0afb2ac 18
mjr 1:d913e0afb2ac 19 #ifndef MMA8451Q_H
mjr 1:d913e0afb2ac 20 #define MMA8451Q_H
mjr 1:d913e0afb2ac 21
mjr 1:d913e0afb2ac 22 #include "mbed.h"
mjr 1:d913e0afb2ac 23
mjr 1:d913e0afb2ac 24 /**
mjr 1:d913e0afb2ac 25 * MMA8451Q accelerometer example
mjr 1:d913e0afb2ac 26 *
mjr 1:d913e0afb2ac 27 * @code
mjr 1:d913e0afb2ac 28 * #include "mbed.h"
mjr 1:d913e0afb2ac 29 * #include "MMA8451Q.h"
mjr 1:d913e0afb2ac 30 *
mjr 1:d913e0afb2ac 31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
mjr 1:d913e0afb2ac 32 *
mjr 1:d913e0afb2ac 33 * int main(void) {
mjr 1:d913e0afb2ac 34 *
mjr 1:d913e0afb2ac 35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
mjr 1:d913e0afb2ac 36 * PwmOut rled(LED_RED);
mjr 1:d913e0afb2ac 37 * PwmOut gled(LED_GREEN);
mjr 1:d913e0afb2ac 38 * PwmOut bled(LED_BLUE);
mjr 1:d913e0afb2ac 39 *
mjr 1:d913e0afb2ac 40 * while (true) {
mjr 1:d913e0afb2ac 41 * rled = 1.0 - abs(acc.getAccX());
mjr 1:d913e0afb2ac 42 * gled = 1.0 - abs(acc.getAccY());
mjr 1:d913e0afb2ac 43 * bled = 1.0 - abs(acc.getAccZ());
mjr 1:d913e0afb2ac 44 * wait(0.1);
mjr 1:d913e0afb2ac 45 * }
mjr 1:d913e0afb2ac 46 * }
mjr 1:d913e0afb2ac 47 * @endcode
mjr 1:d913e0afb2ac 48 */
mjr 1:d913e0afb2ac 49 class MMA8451Q
mjr 1:d913e0afb2ac 50 {
mjr 1:d913e0afb2ac 51 public:
mjr 1:d913e0afb2ac 52 /**
mjr 1:d913e0afb2ac 53 * MMA8451Q constructor
mjr 1:d913e0afb2ac 54 *
mjr 1:d913e0afb2ac 55 * @param sda SDA pin
mjr 1:d913e0afb2ac 56 * @param sdl SCL pin
mjr 1:d913e0afb2ac 57 * @param addr addr of the I2C peripheral
mjr 1:d913e0afb2ac 58 */
mjr 1:d913e0afb2ac 59 MMA8451Q(PinName sda, PinName scl, int addr);
mjr 1:d913e0afb2ac 60
mjr 1:d913e0afb2ac 61 /**
mjr 1:d913e0afb2ac 62 * MMA8451Q destructor
mjr 1:d913e0afb2ac 63 */
mjr 1:d913e0afb2ac 64 ~MMA8451Q();
mjr 1:d913e0afb2ac 65
mjr 1:d913e0afb2ac 66 /**
mjr 1:d913e0afb2ac 67 * Enter standby mode
mjr 1:d913e0afb2ac 68 */
mjr 1:d913e0afb2ac 69 void standby();
mjr 1:d913e0afb2ac 70
mjr 1:d913e0afb2ac 71 /**
mjr 1:d913e0afb2ac 72 * Enter active mode
mjr 1:d913e0afb2ac 73 */
mjr 1:d913e0afb2ac 74 void active();
mjr 1:d913e0afb2ac 75
mjr 1:d913e0afb2ac 76 /**
mjr 1:d913e0afb2ac 77 * Get the value of the WHO_AM_I register
mjr 1:d913e0afb2ac 78 *
mjr 1:d913e0afb2ac 79 * @returns WHO_AM_I value
mjr 1:d913e0afb2ac 80 */
mjr 1:d913e0afb2ac 81 uint8_t getWhoAmI();
mjr 1:d913e0afb2ac 82
mjr 1:d913e0afb2ac 83 /**
mjr 1:d913e0afb2ac 84 * Get X axis acceleration
mjr 1:d913e0afb2ac 85 *
mjr 1:d913e0afb2ac 86 * @returns X axis acceleration
mjr 1:d913e0afb2ac 87 */
mjr 1:d913e0afb2ac 88 float getAccX();
mjr 1:d913e0afb2ac 89
mjr 1:d913e0afb2ac 90 /**
mjr 1:d913e0afb2ac 91 * Get Y axis acceleration
mjr 1:d913e0afb2ac 92 *
mjr 1:d913e0afb2ac 93 * @returns Y axis acceleration
mjr 1:d913e0afb2ac 94 */
mjr 1:d913e0afb2ac 95 float getAccY();
mjr 1:d913e0afb2ac 96
mjr 1:d913e0afb2ac 97 /**
mjr 1:d913e0afb2ac 98 * Read an X,Y pair
mjr 1:d913e0afb2ac 99 */
mjr 1:d913e0afb2ac 100 void getAccXY(float &x, float &y);
mjr 3:3514575d4f86 101
mjr 3:3514575d4f86 102 /**
mjr 3:3514575d4f86 103 * Read X,Y,Z. This is the most efficient way to fetch
mjr 3:3514575d4f86 104 * all of the axes at once, since it fetches all three
mjr 3:3514575d4f86 105 * in a single I2C transaction.
mjr 3:3514575d4f86 106 */
mjr 3:3514575d4f86 107 void getAccXYZ(float &x, float &y, float &z);
mjr 1:d913e0afb2ac 108
mjr 1:d913e0afb2ac 109 /**
mjr 1:d913e0afb2ac 110 * Get Z axis acceleration
mjr 1:d913e0afb2ac 111 *
mjr 1:d913e0afb2ac 112 * @returns Z axis acceleration
mjr 1:d913e0afb2ac 113 */
mjr 1:d913e0afb2ac 114 float getAccZ();
mjr 1:d913e0afb2ac 115
mjr 1:d913e0afb2ac 116 /**
mjr 1:d913e0afb2ac 117 * Get XYZ axis acceleration
mjr 1:d913e0afb2ac 118 *
mjr 1:d913e0afb2ac 119 * @param res array where acceleration data will be stored
mjr 1:d913e0afb2ac 120 */
mjr 1:d913e0afb2ac 121 void getAccAllAxis(float * res);
mjr 3:3514575d4f86 122
mjr 3:3514575d4f86 123 /**
mjr 3:3514575d4f86 124 * Set interrupt mode. 'pin' is 1 for INT1_ACCEL (PTA14) and 2 for INT2_ACCEL (PTA15).
mjr 3:3514575d4f86 125 * The caller is responsible for setting up an interrupt handler on the corresponding
mjr 3:3514575d4f86 126 * PTAxx pin.
mjr 3:3514575d4f86 127 */
mjr 3:3514575d4f86 128 void setInterruptMode(int pin);
mjr 1:d913e0afb2ac 129
mjr 1:d913e0afb2ac 130 private:
mjr 1:d913e0afb2ac 131 I2C m_i2c;
mjr 1:d913e0afb2ac 132 int m_addr;
mjr 1:d913e0afb2ac 133 void readRegs(int addr, uint8_t * data, int len);
mjr 1:d913e0afb2ac 134 void writeRegs(uint8_t * data, int len);
mjr 1:d913e0afb2ac 135 int16_t getAccAxis(uint8_t addr);
mjr 1:d913e0afb2ac 136
mjr 1:d913e0afb2ac 137 };
mjr 1:d913e0afb2ac 138
mjr 1:d913e0afb2ac 139 #endif