Touch sensor example for NXP Rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011.
Revision 82:a325ac3c1b73, committed 2019-12-27
- Comitter:
- batman52
- Date:
- Fri Dec 27 15:17:32 2019 +0000
- Parent:
- 81:7a20aa99834e
- Commit message:
- now supports IRQ instead of polling
Changed in this revision
lib_sx9500.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lib_sx9500.lib Thu Dec 19 17:07:35 2019 +0000 +++ b/lib_sx9500.lib Fri Dec 27 15:17:32 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/batman52/code/lib_sx9500/#f88a77463a32 +https://os.mbed.com/users/batman52/code/lib_sx9500/#b0a2ba594005
--- a/main.cpp Thu Dec 19 17:07:35 2019 +0000 +++ b/main.cpp Fri Dec 27 15:17:32 2019 +0000 @@ -1,10 +1,27 @@ #include "mbed.h" #include "sx9500.h" +#define IRQ_EN 1 + I2C i2c0(I2C_SDA , I2C_SCL ); // I2C_SCL = PTC10, I2C_SDA = PTC11, SX9500 touch(i2c0, PTA24, PTA9); // TOUCH_TXEN = PTA24, TOUCH_INT = PTA9 DigitalOut touch_rst(PTA2,1); // TOUCH_RST = PTA2 +bool read_en = true; + +#if(IRQ_EN) +// InterruptIn SW1(PTE28); +InterruptIn touch_int(PTA9); +/* LEDS */ +DigitalOut led_red(LED_RED, 1); + +void touch_irq() +{ + read_en = true; + led_red = !led_red; +} +#endif // IRQ_EN + void print_state(SX9500_TouchState_t ts) { if(ts.downPressed) @@ -19,24 +36,39 @@ printf("NONE\r\n"); } +void touch_service() +{ +SX9500_TouchState_t ts; +read_en = false; +ts = touch.read_proximity_sensors(); +print_state(ts); +// reset interrupt state +touch.service(); +} + // main() runs in its own thread in the OS int main() { - SX9500_TouchState_t ts; - - wait(1); - + + wait(1); touch.reset(); wait(0.3); // wait until the reset has finished touch.init(); wait(0.3); touch.set_active(true); wait(0.3); - + +#if(IRQ_EN) + touch_int.fall(&touch_irq); + // SW1.fall(&touch_irq); + read_en = false; +#endif + while (true) { - +#if(!IRQ_EN) + read_en = true; +#endif wait(0.3); - ts = touch.read_proximity_sensors(); - print_state(ts); - + if(read_en) + touch_service(); } }