Code for a robotic pet to interact with.

Dependencies:   mbed wave_player Servo Motordriver mbed-rtos 4DGL-uLCD-SE SDFileSystem_OldbutworkswithRTOS HC_SR04_Ultrasonic_Library

Committer:
jprocter3
Date:
Mon Apr 22 18:55:43 2019 +0000
Revision:
15:02e772571d48
Parent:
5:d7b32a06799d
fixed i2c interrupt block

Who changed what in which revision?

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