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 :)

Committer:
sam_grove
Date:
Wed Oct 22 15:02:07 2014 -0500
Revision:
2:a37fbc835511
Parent:
1:684222fa16bb
added white space

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:6f4bcfe86ac2 1 #include "mbed.h"
sam_grove 0:6f4bcfe86ac2 2 #include "MPR121.h"
sam_grove 0:6f4bcfe86ac2 3
sam_grove 1:684222fa16bb 4 Serial pc(USBTX, USBRX);
sam_grove 0:6f4bcfe86ac2 5 DigitalOut myled(LED1);
sam_grove 1:684222fa16bb 6
sam_grove 1:684222fa16bb 7 #if defined TARGET_LPC1768 || TARGET_LPC11U24
sam_grove 1:684222fa16bb 8 I2C i2c(p28, p27);
sam_grove 1:684222fa16bb 9 InterruptIn irq(p26);
sam_grove 1:684222fa16bb 10 MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 0:6f4bcfe86ac2 11
sam_grove 1:684222fa16bb 12 #elif defined TARGET_KL25Z
sam_grove 1:684222fa16bb 13 I2C i2c(PTC9, PTC8);
sam_grove 1:684222fa16bb 14 InterruptIn irq(PTA5);
sam_grove 1:684222fa16bb 15 MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS);
sam_grove 0:6f4bcfe86ac2 16
sam_grove 1:684222fa16bb 17 #else
sam_grove 1:684222fa16bb 18 #error TARGET NOT TESTED
sam_grove 1:684222fa16bb 19 #endif
sam_grove 0:6f4bcfe86ac2 20
sam_grove 0:6f4bcfe86ac2 21 int main()
sam_grove 0:6f4bcfe86ac2 22 {
sam_grove 0:6f4bcfe86ac2 23 touch_pad.init();
sam_grove 0:6f4bcfe86ac2 24 touch_pad.enable();
sam_grove 1:684222fa16bb 25 touch_pad.registerDump(pc);
sam_grove 1:684222fa16bb 26
sam_grove 0:6f4bcfe86ac2 27 while(1)
sam_grove 0:6f4bcfe86ac2 28 {
sam_grove 0:6f4bcfe86ac2 29 if(touch_pad.isPressed())
sam_grove 0:6f4bcfe86ac2 30 {
sam_grove 0:6f4bcfe86ac2 31 uint16_t button_val = touch_pad.buttonPressed();
sam_grove 1:684222fa16bb 32 printf("button = 0x%04x\n", button_val);
sam_grove 0:6f4bcfe86ac2 33 myled = (button_val>0) ? 1 : 0;
sam_grove 1:684222fa16bb 34 }
sam_grove 0:6f4bcfe86ac2 35 }
sam_grove 0:6f4bcfe86ac2 36 }
sam_grove 2:a37fbc835511 37