8 Replies Latest reply on Nov 19, 2020 8:27 PM by AH_96

    How to toggle led on/off using Capsense button

    AjSi_4796051

      I am unable to get smoth operation of toggling led using self capacitance  CapSense button

        • 1. Re: How to toggle led on/off using Capsense button
          GaneshD_41

          Hi,

           

          Please find the attached projects where the operation is as follows:

           

          Project 1:

          Configured two buttons such that an LED in the kit glows whenever the button is pressed. Send the status of the button through UART only when the status changes. That is, transmit “Button Pressed” or “Button Released” through UART whenever the button is pressed/released respectively and this must only be sent once per change.

           

          Project2:

          Configured a linear slider such that the brightness of an LED is adjusted by the finger position and the position must be sent over through UART. Again, it must be sent only once per value. Same value must not be repeated multiple times consecutively.

           

          Hope these helps !

           

          Thanks

          Ganesh

          1 of 1 people found this helpful
          • 2. Re: How to toggle led on/off using Capsense button
            AjSi_4796051

            Hi ganesh ,

            Tnx for your reply ,

            I used project 1 to toggle led ( capsense button pressed led become on and then again button pressed led become off )

            But flickerring issue is comming !!

            Any solution for that !!

            1 of 1 people found this helpful
            • 3. Re: How to toggle led on/off using Capsense button
              AH_96

              Hi AjSi_4796051

               

              In your case, the for loop can be much simpler.

               

              for(;;)
              {
                  /* Do this only when a scan is done */
                  if(CapSense_NOT_BUSY == CapSense_IsBusy())
                  {
                      CapSense_ProcessAllWidgets(); /* Process all widgets */
                      CapSense_RunTuner(); /* To sync with Tuner application */
                      if (CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) /* Scan result verification */
                      {
                          GREEN_LED_Write(0);
                      }
                      else 
                      {
                          GREEN_LED_Write(1);
                      } 
                      CapSense_ScanAllWidgets(); /* Start next scan */
                  }
              }
              

               

              Best regards,
              Hari

              • 4. Re: How to toggle led on/off using Capsense button
                AjSi_4796051

                if(CapSense_NOT_BUSY == CapSense_IsBusy())

                     {  

                      

                         CapSense_ProcessAllWidgets(); /* Process all widgets */

                            CapSense_RunTuner(); /* To sync with Tuner application */

                      

                          

                       

                      

                        

                       if (fingerpresent_0 == 0 && CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))

                        {

                          

                             PWM_1_WriteCompare1(255);

                             fingerpresent_0 = 1;

                            

                        }

                         else if (fingerpresent_0 == 1 && CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))

                        {

                          

                             PWM_1_WriteCompare1(10);

                             fingerpresent_0 = 0;

                            

                        }

                 

                 

                 

                my program is like this but when i pressed the button some time it works fine but some time it fluctuate           

                • 5. Re: How to toggle led on/off using Capsense button
                  AH_96

                  Hi AjSi_4796051

                   

                  You need to modify the else if condition to

                  else if (fingerpresent_0 == 1 && !(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)))

                   

                  Notice the negation symbol for the CapSense_IsWidgetActive. This is to turn off the LED only if the widget is not active.

                   

                  Best regards,

                  Hari

                  • 6. Re: How to toggle led on/off using Capsense button
                    AjSi_4796051

                    Hi Hari,

                    thanks for  your reply !!!

                    actually I used the led as a feedback, one tap on button to switch on the LED ,then another tap on button to switch off the LED

                     

                    and as you mentioned , i think it is used for displaying button is active !!!

                     

                    regards

                    ajay

                    • 7. Re: How to toggle led on/off using Capsense button
                      AjSi_4796051

                      Can you guide me , about the code !!

                      • 8. Re: How to toggle led on/off using Capsense button
                        AH_96

                        Hi AjSi_4796051,

                         

                        That logic is fairly simple again. You need to toggle the LED only once on every successful touch detection. So the firmware would be

                         

                         

                         

                        uint8 wdgt_active = 0;
                        for(;;)
                        {
                             if(CapSense_NOT_BUSY == CapSense_IsBusy())
                             {  
                                  CapSense_ProcessAllWidgets(); /* Process all widgets */
                                  CapSense_RunTuner(); /* To sync with Tuner application */
                                  if (fingerpresent_0 == 0 && CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
                                  {
                                       if(wdgt_active == 0)
                                       {
                                            PWM_1_WriteCompare1(255);
                                            wdgt_active = 1;
                                       }
                                       else
                                       {
                                            PWM_1_WriteCompare1(10);
                                            wdgt_active = 0;
                                       }
                        
                                       fingerpresent_0 = 1;
                                  }
                                  else if (fingerpresent_0 == 1 && !CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
                                  {
                                       fingerpresent_0 = 0;
                                  }
                                  CapSense_ScanAllWidgets();
                             }
                        }
                        

                         

                         

                        Best regards,   

                        Hari

                        1 of 1 people found this helpful