Seeed I2C touch example

Dependencies:   MPR121 mbed

Fork of MPR121_HelloWorld by Sam Grove

Committer:
sam_grove
Date:
Fri Jul 26 21:41:55 2013 +0000
Revision:
0:6f4bcfe86ac2
Child:
1:684222fa16bb
Work in progress...

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 0:6f4bcfe86ac2 4 // TODO: put IC in low power mode when disabled
sam_grove 0:6f4bcfe86ac2 5
sam_grove 0:6f4bcfe86ac2 6 DigitalOut myled(LED1);
sam_grove 0:6f4bcfe86ac2 7 DigitalOut off(LED4);
sam_grove 0:6f4bcfe86ac2 8 Timer t;
sam_grove 0:6f4bcfe86ac2 9
sam_grove 0:6f4bcfe86ac2 10 LogUtil logger;
sam_grove 0:6f4bcfe86ac2 11
sam_grove 0:6f4bcfe86ac2 12 I2C i2c(p28, p27);
sam_grove 0:6f4bcfe86ac2 13 InterruptIn irq(p26);
sam_grove 0:6f4bcfe86ac2 14 MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS );
sam_grove 0:6f4bcfe86ac2 15
sam_grove 0:6f4bcfe86ac2 16 int main()
sam_grove 0:6f4bcfe86ac2 17 {
sam_grove 0:6f4bcfe86ac2 18 touch_pad.init();
sam_grove 0:6f4bcfe86ac2 19 touch_pad.enable();
sam_grove 0:6f4bcfe86ac2 20 t.start();
sam_grove 0:6f4bcfe86ac2 21 while(1)
sam_grove 0:6f4bcfe86ac2 22 {
sam_grove 0:6f4bcfe86ac2 23 if(touch_pad.isPressed())
sam_grove 0:6f4bcfe86ac2 24 {
sam_grove 0:6f4bcfe86ac2 25 uint16_t button_val = touch_pad.buttonPressed();
sam_grove 0:6f4bcfe86ac2 26 LOG("button = 0x%04x\n", button_val);
sam_grove 0:6f4bcfe86ac2 27 myled = (button_val>0) ? 1 : 0;
sam_grove 0:6f4bcfe86ac2 28 }
sam_grove 0:6f4bcfe86ac2 29 // if(t.read_ms() > 5000)
sam_grove 0:6f4bcfe86ac2 30 // {
sam_grove 0:6f4bcfe86ac2 31 // touch_pad.disable();
sam_grove 0:6f4bcfe86ac2 32 // off = 1;
sam_grove 0:6f4bcfe86ac2 33 // wait(5.0f);
sam_grove 0:6f4bcfe86ac2 34 // off = 0;
sam_grove 0:6f4bcfe86ac2 35 // touch_pad.enable();
sam_grove 0:6f4bcfe86ac2 36 // t.reset();
sam_grove 0:6f4bcfe86ac2 37 // }
sam_grove 0:6f4bcfe86ac2 38
sam_grove 0:6f4bcfe86ac2 39 }
sam_grove 0:6f4bcfe86ac2 40 }