Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au) 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 #include <mbed.h> 00024 #include <string> 00025 #include <list> 00026 00027 #include <mpr121.h> 00028 00029 // Create the interrupt receiver object on pin 26 00030 InterruptIn interrupt(p26); 00031 00032 // Setup the Serial to the PC for debugging 00033 Serial pc(USBTX, USBRX); 00034 00035 // Setup the i2c bus on pins 28 and 27 00036 I2C i2c(p28, p27); 00037 00038 // Setup the Mpr121: 00039 // constructor(i2c object, i2c address of the mpr121) 00040 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); 00041 00042 void fallInterrupt(){ 00043 int value=mpr121.read(0x00); 00044 value +=mpr121.read(0x01)<<8; 00045 pc.printf("MPR value: %x \r\n", value); 00046 } 00047 00048 int main() { 00049 00050 pc.printf("\nHello from the mbed & mpr121\n\r"); 00051 00052 unsigned char dataArray[2]; 00053 int key; 00054 int count = 0; 00055 00056 pc.printf("Test 1: read a value: \r\n"); 00057 dataArray[0] = mpr121.read(AFE_CFG); 00058 pc.printf("Read value=%x\r\n\n",dataArray[0]); 00059 00060 pc.printf("Test 2: read a value: \r\n"); 00061 dataArray[0] = mpr121.read(0x5d); 00062 pc.printf("Read value=%x\r\n\n",dataArray[0]); 00063 00064 pc.printf("Test 3: write & read a value: \r\n"); 00065 mpr121.read(ELE0_T); 00066 mpr121.write(ELE0_T,0x22); 00067 dataArray[0] = mpr121.read(ELE0_T); 00068 pc.printf("Read value=%x\r\n\n",dataArray[0]); 00069 00070 pc.printf("Test 4: Write many values: \r\n"); 00071 unsigned char data[] = {0x1,0x3,0x5,0x9,0x15,0x25,0x41}; 00072 mpr121.writeMany(0x42,data,7); 00073 00074 // Now read them back .. 00075 key = 0x42; 00076 count = 0; 00077 while(count < 7){ 00078 char result = mpr121.read(key); 00079 key++; 00080 count++; 00081 pc.printf("Read value: '%x'=%x\n\r",key,result); 00082 } 00083 00084 pc.printf("Test 5: Read Electrodes:\r\n"); 00085 key = ELE0_T; 00086 count = 0; 00087 while(count < 24){ 00088 char result = mpr121.read(key); 00089 pc.printf("Read key:%x value:%x\n\r",key,result); 00090 key++; 00091 count++; } 00092 pc.printf("--------- \r\n\n"); 00093 00094 // mpr121.setProximityMode(true); 00095 00096 pc.printf("ELE_CFG=%x", mpr121.read(ELE_CFG)); 00097 00098 interrupt.fall(&fallInterrupt); 00099 interrupt.mode(PullUp); 00100 00101 while(1){ 00102 wait(5); 00103 pc.printf("."); 00104 } 00105 } 00106 00107 00108
Generated on Thu Jul 21 2022 01:20:44 by
1.7.2