/** 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 */

Dependencies:   TSI mbed

/ 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
  • /
Revision:
1:5ec182dbf86d
Parent:
0:64ba2b612c25
--- 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