A security system that detects the movement of an object in a box using IR distance sensors

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

Committer:
tdouglas6
Date:
Tue Dec 09 14:53:24 2014 +0000
Revision:
1:44af7a01e1e0
Parent:
0:a729b4a52c27
Security system that detects the movement of an object in a box.

Who changed what in which revision?

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