/** TSISensor example program * Read the capacitive touch slider of the FRDM-KL25Z board * and control the power of the blue LED accordingly. * * Hardware requirements: * - Freescale FRDM-KL25Z board */
Fork of 04_TSISensor by
Revision 1:5ec182dbf86d, committed 2015-11-03
- Comitter:
- icserny
- Date:
- Tue Nov 03 06:46:36 2015 +0000
- Parent:
- 0:64ba2b612c25
- Commit message:
- First version
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 64ba2b612c25 -r 5ec182dbf86d main.cpp --- a/main.cpp Sat Oct 31 17:22:17 2015 +0000 +++ b/main.cpp Tue Nov 03 06:46:36 2015 +0000 @@ -1,13 +1,21 @@ +/** TSISensor example program + * Read the capacitive touch slider of the FRDM-KL25Z board + * and control the power of the blue LED accordingly. + * + * Hardware requirements: + * - Freescale FRDM-KL25Z board + */ + #include "mbed.h" #include "TSISensor.h" int main(void) { - PwmOut led(LED_BLUE); - TSISensor tsi; - + PwmOut led(LED_BLUE); //Configure a PWM output for the blue LED + TSISensor tsi; //Configure the touch sensing module + led = 1.0; //LED off at the beginning while (true) { - float s = tsi.readPercentage(); - led = 1.0 - s*s; - wait(0.1); + float s = tsi.readPercentage(); //Read slider status + if (s > 0.01) led = 1.0 - s; //Control LED power if touch occurred + wait(0.1); //wait a little... } } \ No newline at end of file