cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

adpac_1560036
New Contributor II

Hi, I was working with capsense and i require the capsense button to work just as normal push switch.

   

I am using the buttons to send commands to my serial mp3 player. But if i put my finger on the button, the function is getting executed a number of times and sending the UART data continuously which i require to be sent only once.

   

I am uploading my workspace bundle. Please let me know a solution for this

0 Likes
1 Solution
Bob_Marlowe
Expert II

Easiest is to remember the state of the button and react only when its state changes. When the button is pressed for a longer time (a counter will help to detect) you can react differently as fast forward, mute or something else.

   

 

   

Bob

View solution in original post

0 Likes
6 Replies
Bob_Marlowe
Expert II

Easiest is to remember the state of the button and react only when its state changes. When the button is pressed for a longer time (a counter will help to detect) you can react differently as fast forward, mute or something else.

   

 

   

Bob

View solution in original post

0 Likes
adpac_1560036
New Contributor II

oh. okay Bob.Thank you. I will try it out

0 Likes
adpac_1560036
New Contributor II

Bob, could you please elaborate how to save the button state? I tried it out but still it is not executed only once. I tried varying the debounce settings of capsense too..still not working

0 Likes
Bob_Marlowe
Expert II

It has nothing to do with the debouncing of the capsense. Your code shows clearly "As long as the button is pressed execute the prev() function"

   

You have to define a

   

static uint8 Button_Pressed = FALSE;

   

and in code

   

    if(CapSense_CheckIsWidgetActive(CapSense_BUTTON1__BTN) && !Button_Pressed)
    {
        Prev();
        LCD_PrintString("ON  ");

   

        Button_Pressed = TRUE;
    }

   

    else
    {

   

        if(Button_Pressed)   LCD_PrintString("OFF ");

   

        Button_Pressed = FALSE;
    }

   

Might be you have to #define FALSE and TRUE as

   

#define FALSE 0

   

#define TRUE  !FALSE

   

 

   

Bob

adpac_1560036
New Contributor II

Thanks a lot Bob!...It is working.

0 Likes
Bob_Marlowe
Expert II

Great!

   

 

   

Bob

0 Likes