Simple implementation of Guitar Hero with mbed.

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

Committer:
gboggs3
Date:
Mon Mar 14 17:59:32 2016 +0000
Revision:
0:58d424fe40b9
Original working version that received checkoff. 3/14/2016

Who changed what in which revision?

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