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 #include <mbed.h> 00002 #include <mpr121.h> 00003 DigitalOut led1(LED1); 00004 DigitalOut led2(LED2); 00005 DigitalOut led3(LED3); 00006 DigitalOut led4(LED4); 00007 // Create the interrupt receiver object on pin 26 00008 InterruptIn interrupt(p26); 00009 // Setup the i2c bus on pins 9 and 10 00010 I2C i2c(p9, p10); 00011 // Setup the Mpr121: 00012 // constructor(i2c object, i2c address of the mpr121) 00013 Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); 00014 00015 // Key hit/release interrupt routine 00016 void fallInterrupt() { 00017 int key_code=0; 00018 int i=0; 00019 int value=mpr121.read(0x00); 00020 value +=mpr121.read(0x01)<<8; 00021 // LED demo mod 00022 i=0; 00023 // puts key number out to LEDs for demo 00024 for (i=0; i<12; i++) { 00025 if (((value>>i)&0x01)==1) key_code=i+1; 00026 } 00027 led4=key_code & 0x01; 00028 led3=(key_code>>1) & 0x01; 00029 led2=(key_code>>2) & 0x01; 00030 led1=(key_code>>3) & 0x01; 00031 } 00032 00033 int main() { 00034 interrupt.fall(&fallInterrupt); 00035 interrupt.mode(PullUp); 00036 while (1) {} 00037 }
Generated on Wed Jul 20 2022 04:13:00 by
1.7.2