Whack-A-Mole game created using the mbed, capacitive touchpad, and a vibration motor.

Dependencies:   4DGL-uLCD-SE mbed

Committer:
richsua
Date:
Wed Oct 21 18:41:01 2015 +0000
Revision:
0:12260ef28a24
Final Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
richsua 0:12260ef28a24 1 /*
richsua 0:12260ef28a24 2 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
richsua 0:12260ef28a24 3
richsua 0:12260ef28a24 4
richsua 0:12260ef28a24 5 Permission is hereby granted, free of charge, to any person obtaining a copy
richsua 0:12260ef28a24 6 of this software and associated documentation files (the "Software"), to deal
richsua 0:12260ef28a24 7 in the Software without restriction, including without limitation the rights
richsua 0:12260ef28a24 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
richsua 0:12260ef28a24 9 copies of the Software, and to permit persons to whom the Software is
richsua 0:12260ef28a24 10 furnished to do so, subject to the following conditions:
richsua 0:12260ef28a24 11
richsua 0:12260ef28a24 12 The above copyright notice and this permission notice shall be included in
richsua 0:12260ef28a24 13 all copies or substantial portions of the Software.
richsua 0:12260ef28a24 14
richsua 0:12260ef28a24 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
richsua 0:12260ef28a24 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
richsua 0:12260ef28a24 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
richsua 0:12260ef28a24 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
richsua 0:12260ef28a24 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
richsua 0:12260ef28a24 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
richsua 0:12260ef28a24 21 THE SOFTWARE.
richsua 0:12260ef28a24 22
richsua 0:12260ef28a24 23 Parts written by Jim Lindblom of Sparkfun
richsua 0:12260ef28a24 24 Ported to mbed by A.Buckton, Feb 2011
richsua 0:12260ef28a24 25 */
richsua 0:12260ef28a24 26
richsua 0:12260ef28a24 27 #ifndef MPR121_H
richsua 0:12260ef28a24 28 #define MPR121_H
richsua 0:12260ef28a24 29
richsua 0:12260ef28a24 30 //using namespace std;
richsua 0:12260ef28a24 31
richsua 0:12260ef28a24 32 class Mpr121
richsua 0:12260ef28a24 33 {
richsua 0:12260ef28a24 34
richsua 0:12260ef28a24 35 public:
richsua 0:12260ef28a24 36 // i2c Addresses, bit-shifted
richsua 0:12260ef28a24 37 enum Address { ADD_VSS = 0xb4,// ADD->VSS = 0x5a <-wiring on Sparkfun board
richsua 0:12260ef28a24 38 ADD_VDD = 0xb6,// ADD->VDD = 0x5b
richsua 0:12260ef28a24 39 ADD_SCL = 0xb8,// ADD->SDA = 0x5c
richsua 0:12260ef28a24 40 ADD_SDA = 0xba // ADD->SCL = 0x5d
richsua 0:12260ef28a24 41 };
richsua 0:12260ef28a24 42
richsua 0:12260ef28a24 43 // Real initialiser, takes the i2c address of the device.
richsua 0:12260ef28a24 44 Mpr121(I2C *i2c, Address i2cAddress);
richsua 0:12260ef28a24 45
richsua 0:12260ef28a24 46 bool getProximityMode();
richsua 0:12260ef28a24 47
richsua 0:12260ef28a24 48 void setProximityMode(bool mode);
richsua 0:12260ef28a24 49
richsua 0:12260ef28a24 50 int readTouchData();
richsua 0:12260ef28a24 51
richsua 0:12260ef28a24 52 unsigned char read(int key);
richsua 0:12260ef28a24 53
richsua 0:12260ef28a24 54 int write(int address, unsigned char value);
richsua 0:12260ef28a24 55 int writeMany(int start, unsigned char* dataSet, int length);
richsua 0:12260ef28a24 56
richsua 0:12260ef28a24 57 void setElectrodeThreshold(int electrodeId, unsigned char touchThreshold, unsigned char releaseThreshold);
richsua 0:12260ef28a24 58
richsua 0:12260ef28a24 59 protected:
richsua 0:12260ef28a24 60 // Configures the MPR with standard settings. This is permitted to be overwritten by sub-classes.
richsua 0:12260ef28a24 61 void configureSettings();
richsua 0:12260ef28a24 62
richsua 0:12260ef28a24 63 private:
richsua 0:12260ef28a24 64 // The I2C bus instance.
richsua 0:12260ef28a24 65 I2C *i2c;
richsua 0:12260ef28a24 66
richsua 0:12260ef28a24 67 // i2c address of this mpr121
richsua 0:12260ef28a24 68 Address address;
richsua 0:12260ef28a24 69 };
richsua 0:12260ef28a24 70
richsua 0:12260ef28a24 71
richsua 0:12260ef28a24 72 // MPR121 Register Defines
richsua 0:12260ef28a24 73 #define MHD_R 0x2B
richsua 0:12260ef28a24 74 #define NHD_R 0x2C
richsua 0:12260ef28a24 75 #define NCL_R 0x2D
richsua 0:12260ef28a24 76 #define FDL_R 0x2E
richsua 0:12260ef28a24 77 #define MHD_F 0x2F
richsua 0:12260ef28a24 78 #define NHD_F 0x30
richsua 0:12260ef28a24 79 #define NCL_F 0x31
richsua 0:12260ef28a24 80 #define FDL_F 0x32
richsua 0:12260ef28a24 81 #define NHDT 0x33
richsua 0:12260ef28a24 82 #define NCLT 0x34
richsua 0:12260ef28a24 83 #define FDLT 0x35
richsua 0:12260ef28a24 84 // Proximity sensing controls
richsua 0:12260ef28a24 85 #define MHDPROXR 0x36
richsua 0:12260ef28a24 86 #define NHDPROXR 0x37
richsua 0:12260ef28a24 87 #define NCLPROXR 0x38
richsua 0:12260ef28a24 88 #define FDLPROXR 0x39
richsua 0:12260ef28a24 89 #define MHDPROXF 0x3A
richsua 0:12260ef28a24 90 #define NHDPROXF 0x3B
richsua 0:12260ef28a24 91 #define NCLPROXF 0x3C
richsua 0:12260ef28a24 92 #define FDLPROXF 0x3D
richsua 0:12260ef28a24 93 #define NHDPROXT 0x3E
richsua 0:12260ef28a24 94 #define NCLPROXT 0x3F
richsua 0:12260ef28a24 95 #define FDLPROXT 0x40
richsua 0:12260ef28a24 96 // Electrode Touch/Release thresholds
richsua 0:12260ef28a24 97 #define ELE0_T 0x41
richsua 0:12260ef28a24 98 #define ELE0_R 0x42
richsua 0:12260ef28a24 99 #define ELE1_T 0x43
richsua 0:12260ef28a24 100 #define ELE1_R 0x44
richsua 0:12260ef28a24 101 #define ELE2_T 0x45
richsua 0:12260ef28a24 102 #define ELE2_R 0x46
richsua 0:12260ef28a24 103 #define ELE3_T 0x47
richsua 0:12260ef28a24 104 #define ELE3_R 0x48
richsua 0:12260ef28a24 105 #define ELE4_T 0x49
richsua 0:12260ef28a24 106 #define ELE4_R 0x4A
richsua 0:12260ef28a24 107 #define ELE5_T 0x4B
richsua 0:12260ef28a24 108 #define ELE5_R 0x4C
richsua 0:12260ef28a24 109 #define ELE6_T 0x4D
richsua 0:12260ef28a24 110 #define ELE6_R 0x4E
richsua 0:12260ef28a24 111 #define ELE7_T 0x4F
richsua 0:12260ef28a24 112 #define ELE7_R 0x50
richsua 0:12260ef28a24 113 #define ELE8_T 0x51
richsua 0:12260ef28a24 114 #define ELE8_R 0x52
richsua 0:12260ef28a24 115 #define ELE9_T 0x53
richsua 0:12260ef28a24 116 #define ELE9_R 0x54
richsua 0:12260ef28a24 117 #define ELE10_T 0x55
richsua 0:12260ef28a24 118 #define ELE10_R 0x56
richsua 0:12260ef28a24 119 #define ELE11_T 0x57
richsua 0:12260ef28a24 120 #define ELE11_R 0x58
richsua 0:12260ef28a24 121 // Proximity Touch/Release thresholds
richsua 0:12260ef28a24 122 #define EPROXTTH 0x59
richsua 0:12260ef28a24 123 #define EPROXRTH 0x5A
richsua 0:12260ef28a24 124 // Debounce configuration
richsua 0:12260ef28a24 125 #define DEB_CFG 0x5B
richsua 0:12260ef28a24 126 // AFE- Analogue Front End configuration
richsua 0:12260ef28a24 127 #define AFE_CFG 0x5C
richsua 0:12260ef28a24 128 // Filter configuration
richsua 0:12260ef28a24 129 #define FIL_CFG 0x5D
richsua 0:12260ef28a24 130 // Electrode configuration - transistions to "active mode"
richsua 0:12260ef28a24 131 #define ELE_CFG 0x5E
richsua 0:12260ef28a24 132
richsua 0:12260ef28a24 133 #define GPIO_CTRL0 0x73
richsua 0:12260ef28a24 134 #define GPIO_CTRL1 0x74
richsua 0:12260ef28a24 135 #define GPIO_DATA 0x75
richsua 0:12260ef28a24 136 #define GPIO_DIR 0x76
richsua 0:12260ef28a24 137 #define GPIO_EN 0x77
richsua 0:12260ef28a24 138 #define GPIO_SET 0x78
richsua 0:12260ef28a24 139 #define GPIO_CLEAR 0x79
richsua 0:12260ef28a24 140 #define GPIO_TOGGLE 0x7A
richsua 0:12260ef28a24 141 // Auto configration registers
richsua 0:12260ef28a24 142 #define AUTO_CFG_0 0x7B
richsua 0:12260ef28a24 143 #define AUTO_CFG_U 0x7D
richsua 0:12260ef28a24 144 #define AUTO_CFG_L 0x7E
richsua 0:12260ef28a24 145 #define AUTO_CFG_T 0x7F
richsua 0:12260ef28a24 146
richsua 0:12260ef28a24 147 // Threshold defaults
richsua 0:12260ef28a24 148 // Electrode touch threshold
richsua 0:12260ef28a24 149 #define E_THR_T 0x0F
richsua 0:12260ef28a24 150 // Electrode release threshold
richsua 0:12260ef28a24 151 #define E_THR_R 0x0A
richsua 0:12260ef28a24 152 // Prox touch threshold
richsua 0:12260ef28a24 153 #define PROX_THR_T 0x02
richsua 0:12260ef28a24 154 // Prox release threshold
richsua 0:12260ef28a24 155 #define PROX_THR_R 0x02
richsua 0:12260ef28a24 156
richsua 0:12260ef28a24 157 #endif