IR Sensor Security System using a touch keypad, micro SD reader and a speaker.

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

Committer:
coconnell7
Date:
Fri Mar 13 03:49:26 2015 +0000
Revision:
0:038ed656f129
1st Revision

Who changed what in which revision?

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