![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Complete
Diff: main.cpp
- Revision:
- 3:ecfa4fa0b5a7
- Parent:
- 2:029b0a855b82
--- a/main.cpp Sat Jan 30 02:34:55 2016 +0000 +++ b/main.cpp Sat Jan 30 03:22:41 2016 +0000 @@ -9,7 +9,7 @@ #include "wdt.h" #include "MCP23S17.h" #include "Nav_Switch.h" - +#include "mpr121.h" DigitalOut LED_1(p21); @@ -19,6 +19,35 @@ DigitalIn switch3(p25); DigitalIn switch4(p26); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + + +InterruptIn interrupt(p27); + +I2C i2c(p9, p10); +Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); + +void fallInterrupt() { + int key_code=0; + int i=0; + int value=mpr121.read(0x00); + value +=mpr121.read(0x01)<<8; + // LED demo mod by J. Hamblen + //pc.printf("MPR value: %x \r\n", value); + i=0; + // puts key number out to LEDs for demo + for (i=0; i<12; i++) { + if (((value>>i)&0x01)==1) key_code=i+1; + } + led4=key_code & 0x01; + led3=(key_code>>1) & 0x01; + led2=(key_code>>2) & 0x01; + led1=(key_code>>3) & 0x01; +} + // Create an SPI bus SPI spi(p5, p6, p7); @@ -37,7 +66,8 @@ _pins.mode(PullUp); Nav_Switch myNav( p18, p15, p16, p19, p17); - + interrupt.fall(&fallInterrupt); + interrupt.mode(PullUp); char Opcode = 0x40; MCP23S17 chip(spi, p20, Opcode);