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

PSoC™ 5, 3 & 1 Forum Discussions

adpac_1560036
Level 4
Level 4
First like received First like given

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
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes

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

0 Likes

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
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Great!

   

 

   

Bob

0 Likes