Test program for capacitive sensing using the Freescale MPR121 on the Sparkfun SEN-10250 BoB

Dependencies:   MPR121 mbed

Fork of MPR121_HelloWorld by Sam Grove

Hello World program that prints the bit mapped value of the electrode that is detected to the console. Also lights a LED when a press or no press state is detected.

Hardware tested:

https://www.sparkfun.com/products/10250

Platforms tested:

Information

Must add pull-ups to the I2C bus!!

LED indication for LPC1768 & LPC11U24 are opposite of KL25Z. See schematics for details :)

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Tue Aug 27 21:43:28 2013 +0000
Parent:
0:6f4bcfe86ac2
Child:
2:a37fbc835511
Commit message:
Updated demo app and tested with LPC1768, LPC11U24 and KL25Z

Changed in this revision

LogUtil.lib Show diff for this revision Revisions of this file
MPR121.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/LogUtil.lib	Fri Jul 26 21:41:55 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/sam_grove/code/LogUtil/#ef45bd2cd9bb
--- a/MPR121.lib	Fri Jul 26 21:41:55 2013 +0000
+++ b/MPR121.lib	Tue Aug 27 21:43:28 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/sam_grove/code/MPR121/#4c0d4b90a3ed
+http://mbed.org/users/sam_grove/code/MPR121/#828260f21de6
--- a/main.cpp	Fri Jul 26 21:41:55 2013 +0000
+++ b/main.cpp	Tue Aug 27 21:43:28 2013 +0000
@@ -1,40 +1,36 @@
 #include "mbed.h"
 #include "MPR121.h"
 
-// TODO: put IC in low power mode when disabled
-
+Serial pc(USBTX, USBRX);
 DigitalOut myled(LED1);
-DigitalOut off(LED4);
-Timer t;
+
+#if defined TARGET_LPC1768 || TARGET_LPC11U24
+  I2C i2c(p28, p27);
+  InterruptIn irq(p26);
+  MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
 
-LogUtil logger;
+#elif defined TARGET_KL25Z
+  I2C i2c(PTC9, PTC8);
+  InterruptIn irq(PTA5);
+  MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
 
-I2C i2c(p28, p27);
-InterruptIn irq(p26);
-MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS );
+#else
+  #error TARGET NOT TESTED
+#endif
 
 int main() 
 {       
     touch_pad.init();
     touch_pad.enable();
-    t.start();
+    touch_pad.registerDump(pc);
+    
     while(1)
     {
         if(touch_pad.isPressed())
         {
             uint16_t button_val = touch_pad.buttonPressed();
-            LOG("button = 0x%04x\n", button_val);
+            printf("button = 0x%04x\n", button_val);
             myled = (button_val>0) ? 1 : 0;
-        }
-//        if(t.read_ms() > 5000)
-//        {
-//            touch_pad.disable();
-//            off = 1;
-//            wait(5.0f);
-//            off = 0;
-//            touch_pad.enable();
-//            t.reset();
-//        }
-            
+        }            
     }
 }
--- a/mbed.bld	Fri Jul 26 21:41:55 2013 +0000
+++ b/mbed.bld	Tue Aug 27 21:43:28 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb
\ No newline at end of file