CapSense touch on release

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
saurabh
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

Hello, 

I am working on CY8c4245AXI-483 capsense. I have successfully implemented touch detection functionality. In need to operate the touch button so that its associated function gets processed after releasing the touch on specified button. For reference I have attached the snippet which I have used.

Any suggestion on how I could achieve the required result?

int main(void)
{
error_uart = 0;
CyGlobalIntEnable; /* Enable global interrupts. */
/* Start UART operation */

UART_Start();
CapSense_Start();

/* Initialization */
CapSense_InitializeAllBaselines();
CapSense_ScanEnabledWidgets();

for(;;)
{

if(!CapSense_IsBusy()){
   if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){
    if(appliance_state[0]==0){
      appliance_state[0]=1;
       UART_UartPutString("ON");
       LED_Write(1);
     }
     else if(appliance_state[0]==1){
        appliance_state[0]=0;
         UART_UartPutString("OFF");
         LED_Write(0);
       }
      }
    }
  }
    CapSense_UpdateEnabledBaselines();
    CapSense_ScanEnabledWidgets();
}

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @saurabh 

 

I missed a parenthesis. your logic should be outside the 

if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){

 

That is, the code would be

int main(void)
{
error_uart = 0;
CyGlobalIntEnable; /* Enable global interrupts. */
/* Start UART operation */

UART_Start();
CapSense_Start();

/* Initialization */
CapSense_InitializeAllBaselines();
CapSense_ScanEnabledWidgets();

for(;;)
{

if(!CapSense_IsBusy()){
   if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){
    if(appliance_state[0]==0){
      appliance_state[0]=1;
       UART_UartPutString("ON");
       LED_Write(1);
     }
      }
       else if(appliance_state[0]==1){
        appliance_state[0]=0;
        Lift_Off_Function_Call();
         UART_UartPutString("OFF");
         LED_Write(0);
       }
    }
  }
    CapSense_UpdateEnabledBaselines();
    CapSense_ScanEnabledWidgets();
}

 

Can you try this one out?

 

Best regards, 
Hari

View solution in original post

4 Replies
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @saurabh 

 

You just need to call the function inside the else if. That is getting executed only on lift-off condition - where the sensor was active and the finger was taken away. So, the code would be 

 

int main(void)
{
error_uart = 0;
CyGlobalIntEnable; /* Enable global interrupts. */
/* Start UART operation */

UART_Start();
CapSense_Start();

/* Initialization */
CapSense_InitializeAllBaselines();
CapSense_ScanEnabledWidgets();

for(;;)
{

if(!CapSense_IsBusy()){
   if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){
    if(appliance_state[0]==0){
      appliance_state[0]=1;
       UART_UartPutString("ON");
       LED_Write(1);
     }
     else if(appliance_state[0]==1){
        appliance_state[0]=0;
        Lift_Off_Function_Call();
         UART_UartPutString("OFF");
         LED_Write(0);
       }
      }
    }
  }
    CapSense_UpdateEnabledBaselines();
    CapSense_ScanEnabledWidgets();
}

Note that I have called the function Lift_Off_Function_Call inside the statement.

 

Do let us know if this is what you were looking for 🙂 

 

Best regards, 
Hari

0 Likes
saurabh
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

Hello @Hari , Thank you for the help but I did not get any response from mcu by applying above logic.

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @saurabh 

 

I missed a parenthesis. your logic should be outside the 

if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){

 

That is, the code would be

int main(void)
{
error_uart = 0;
CyGlobalIntEnable; /* Enable global interrupts. */
/* Start UART operation */

UART_Start();
CapSense_Start();

/* Initialization */
CapSense_InitializeAllBaselines();
CapSense_ScanEnabledWidgets();

for(;;)
{

if(!CapSense_IsBusy()){
   if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){
    if(appliance_state[0]==0){
      appliance_state[0]=1;
       UART_UartPutString("ON");
       LED_Write(1);
     }
      }
       else if(appliance_state[0]==1){
        appliance_state[0]=0;
        Lift_Off_Function_Call();
         UART_UartPutString("OFF");
         LED_Write(0);
       }
    }
  }
    CapSense_UpdateEnabledBaselines();
    CapSense_ScanEnabledWidgets();
}

 

Can you try this one out?

 

Best regards, 
Hari

saurabh
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

@Hari , Thanks a lot, the code is working fine now.

 if(!CapSense_IsBusy()){
   if(CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){        
        flag = 1;
    }
    else if(!CapSense_CheckIsWidgetActive(CapSense_BUTTON0__BTN)){
        if(flag == 1){
        flag = 0;
        if(appliance_state[0]==0){
            appliance_state[0]=1;
            UART_UartPutString("ON");
            LED_Write(1);
        }
        else if(appliance_state[0]==1){
            appliance_state[0]=0;            
            UART_UartPutString("OFF");
            LED_Write(0);
       }
      }
    }
    }
    CapSense_UpdateEnabledBaselines();
    CapSense_ScanEnabledWidgets();
0 Likes