- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @Hari , Thank you for the help but I did not get any response from mcu by applying above logic.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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();