Seeed I2C touch example

Dependencies:   MPR121 mbed

Fork of MPR121_HelloWorld by Sam Grove

Committer:
sam_grove
Date:
Tue Aug 27 21:43:28 2013 +0000
Revision:
1:684222fa16bb
Parent:
0:6f4bcfe86ac2
Child:
2:383e257538ff
Updated demo app and tested with LPC1768, LPC11U24 and KL25Z

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 }