A device driver for the Freescale MPR121 capactive touch IC. Not optimized for any particular system, just a starting point to get the chip up in running in no time. Changes to registers init() method will tailor the library for end system use.

Dependents:   Seeed_Grove_I2C_Touch_Example MPR121_HelloWorld mbed_petbottle_holder_shikake test_DEV-10508 ... more

Datasheet:

http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf

Information

Must add pull-ups to the I2C bus!!

Revision:
2:4c0d4b90a3ed
Parent:
1:cee45334b36a
Child:
3:828260f21de6
--- a/MPR121.h	Thu Mar 07 23:57:27 2013 +0000
+++ b/MPR121.h	Fri Mar 29 21:32:38 2013 +0000
@@ -24,42 +24,52 @@
 #define MPR121_H
 
 #include "mbed.h"
+#include "LogUtil.h"
 
 /** Using the Sparkfun SEN-10250
  *
  * Example:
  * @code
- *  #include "mbed.h"
- *  #include "MPR121.h"
- *
- *  DigitalOut myled(LED1);
- *  Serial pc(USBTX, USBRX);
+ * #include "mbed.h"
+ * #include "MPR121.h"
+ * 
+ * // TODO: put IC in low power mode when disabled
  * 
- *  I2C i2c(p28, p27);
- *  InterruptIn irq(p26);
- *  MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
+ * DigitalOut myled(LED1);
+ * DigitalOut off(LED4);
+ * Timer t;
+ * 
+ * LogUtil logger;
+ * 
+ * I2C i2c(p28, p27);
+ * InterruptIn irq(p26);
+ * MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
  * 
- *  int main() 
- *  {
- *      pc.baud(921600);    // boost the communication speed
- *      printf("\033[2J");  // clear the terminal
- *      printf("\033[1;1H");// and set the cursor to home
- *      wait(0.1f);
- *      printf("*******************************************************\n");
- *         
- *      touch_pad.init();
- *      touch_pad.enable();
- *    
- *      while(1)
- *      {
- *          if(touch_pad.isPressed())
- *          {
- *              uint16_t button_val = touch_pad.buttonPressed();
- *              printf("button = 0x%04x\n", button_val);
- *              myled = (button_val>0) ? 1 : 0;
- *          }    
- *      }
- *  }
+ * int main() 
+ * {       
+ *     touch_pad.init();
+ *     touch_pad.enable();
+ *     t.start();
+ *     while(1)
+ *     {
+ *         if(touch_pad.isPressed())
+ *         {
+ *             uint16_t button_val = touch_pad.buttonPressed();
+ *             LOG("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();
+ *         }
+ *             
+ *     }
+ * }
  * @endcode
  */