3 key touch panel from Seeed
Fork of Seeed_Grove_I2C_Touch_Example by
Revision 9:31065d903a2b, committed 2017-08-03
- Comitter:
- Nathan Yonkee
- Date:
- Thu Aug 03 06:23:18 2017 -0600
- Parent:
- 8:59e43faffe44
- Commit message:
- detect button presses by changing LED blinking rate instead of serial printing
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 59e43faffe44 -r 31065d903a2b main.cpp --- a/main.cpp Sun Jul 02 16:37:58 2017 -0600 +++ b/main.cpp Thu Aug 03 06:23:18 2017 -0600 @@ -3,25 +3,25 @@ #include "MPR121.h" I2C i2c(PA_10, PA_9); -MPR121 touch_pad(i2c, MPR121::ADDR_VSS); -DigitalOut led(PB_3); +MPR121 touch_pad(i2c); +DigitalOut led(PB_4); Serial ser(SERIAL_TX, SERIAL_RX); int main() { - uint32_t button_val = 20; + led = 1; + int waitTime = 200; /* touch_pad.enable(); */ while(1) { /* button_val = touch_pad.buttonPressed(); */ - /* ser.printf("button = 0x%04x\n", button_val); */ - ser.printf("trying\n"); - button_val = touch_pad.isPressed(); - ser.printf("any button pressed is (bool) %i\n",button_val); - button_val = touch_pad.buttonPressed(); - ser.printf("button_val is %i\n",button_val); - Thread::wait(2000); + led = !led; + int whichButton = touch_pad.buttonPressed(); + if(whichButton == 1) waitTime = 100; + if(whichButton == 2) waitTime = 500; + if(whichButton == 4) waitTime = 2000; + Thread::wait(waitTime); } }