Tank Dodger Game

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Committer:
ashankar35
Date:
Tue Mar 14 19:18:48 2017 +0000
Revision:
0:350246c72962
Lab4-FinalGame

Who changed what in which revision?

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