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:
lemming
Date:
Tue Feb 24 05:25:41 2015 +0000
Revision:
15:eb8aac252eba
Parent:
5:a70c0bce770d
Adjusted pinscape to work with a cheap linear potentiometer instead of a CCD array

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 5:a70c0bce770d 65
mjr 5:a70c0bce770d 66 /**
mjr 5:a70c0bce770d 67 * Reset the accelerometer hardware and set our initial parameters
mjr 5:a70c0bce770d 68 */
mjr 5:a70c0bce770d 69 void init();
mjr 1:d913e0afb2ac 70
mjr 1:d913e0afb2ac 71 /**
mjr 1:d913e0afb2ac 72 * Enter standby mode
mjr 1:d913e0afb2ac 73 */
mjr 1:d913e0afb2ac 74 void standby();
mjr 1:d913e0afb2ac 75
mjr 1:d913e0afb2ac 76 /**
mjr 1:d913e0afb2ac 77 * Enter active mode
mjr 1:d913e0afb2ac 78 */
mjr 1:d913e0afb2ac 79 void active();
mjr 1:d913e0afb2ac 80
mjr 1:d913e0afb2ac 81 /**
mjr 1:d913e0afb2ac 82 * Get the value of the WHO_AM_I register
mjr 1:d913e0afb2ac 83 *
mjr 1:d913e0afb2ac 84 * @returns WHO_AM_I value
mjr 1:d913e0afb2ac 85 */
mjr 1:d913e0afb2ac 86 uint8_t getWhoAmI();
mjr 1:d913e0afb2ac 87
mjr 1:d913e0afb2ac 88 /**
mjr 1:d913e0afb2ac 89 * Get X axis acceleration
mjr 1:d913e0afb2ac 90 *
mjr 1:d913e0afb2ac 91 * @returns X axis acceleration
mjr 1:d913e0afb2ac 92 */
mjr 1:d913e0afb2ac 93 float getAccX();
mjr 1:d913e0afb2ac 94
mjr 1:d913e0afb2ac 95 /**
mjr 1:d913e0afb2ac 96 * Get Y axis acceleration
mjr 1:d913e0afb2ac 97 *
mjr 1:d913e0afb2ac 98 * @returns Y axis acceleration
mjr 1:d913e0afb2ac 99 */
mjr 1:d913e0afb2ac 100 float getAccY();
mjr 1:d913e0afb2ac 101
mjr 1:d913e0afb2ac 102 /**
mjr 1:d913e0afb2ac 103 * Read an X,Y pair
mjr 1:d913e0afb2ac 104 */
mjr 1:d913e0afb2ac 105 void getAccXY(float &x, float &y);
mjr 3:3514575d4f86 106
mjr 3:3514575d4f86 107 /**
mjr 3:3514575d4f86 108 * Read X,Y,Z. This is the most efficient way to fetch
mjr 3:3514575d4f86 109 * all of the axes at once, since it fetches all three
mjr 3:3514575d4f86 110 * in a single I2C transaction.
mjr 3:3514575d4f86 111 */
mjr 3:3514575d4f86 112 void getAccXYZ(float &x, float &y, float &z);
mjr 1:d913e0afb2ac 113
mjr 1:d913e0afb2ac 114 /**
mjr 1:d913e0afb2ac 115 * Get Z axis acceleration
mjr 1:d913e0afb2ac 116 *
mjr 1:d913e0afb2ac 117 * @returns Z axis acceleration
mjr 1:d913e0afb2ac 118 */
mjr 1:d913e0afb2ac 119 float getAccZ();
mjr 1:d913e0afb2ac 120
mjr 1:d913e0afb2ac 121 /**
mjr 1:d913e0afb2ac 122 * Get XYZ axis acceleration
mjr 1:d913e0afb2ac 123 *
mjr 1:d913e0afb2ac 124 * @param res array where acceleration data will be stored
mjr 1:d913e0afb2ac 125 */
mjr 1:d913e0afb2ac 126 void getAccAllAxis(float * res);
mjr 3:3514575d4f86 127
mjr 3:3514575d4f86 128 /**
mjr 3:3514575d4f86 129 * Set interrupt mode. 'pin' is 1 for INT1_ACCEL (PTA14) and 2 for INT2_ACCEL (PTA15).
mjr 3:3514575d4f86 130 * The caller is responsible for setting up an interrupt handler on the corresponding
mjr 3:3514575d4f86 131 * PTAxx pin.
mjr 3:3514575d4f86 132 */
mjr 3:3514575d4f86 133 void setInterruptMode(int pin);
mjr 1:d913e0afb2ac 134
mjr 1:d913e0afb2ac 135 private:
mjr 1:d913e0afb2ac 136 I2C m_i2c;
mjr 1:d913e0afb2ac 137 int m_addr;
mjr 1:d913e0afb2ac 138 void readRegs(int addr, uint8_t * data, int len);
mjr 1:d913e0afb2ac 139 void writeRegs(uint8_t * data, int len);
mjr 1:d913e0afb2ac 140 int16_t getAccAxis(uint8_t addr);
mjr 1:d913e0afb2ac 141
mjr 1:d913e0afb2ac 142 };
mjr 1:d913e0afb2ac 143
mjr 1:d913e0afb2ac 144 #endif