- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hai,
I am tring to use capsense to increment a variable (s) (CY8CKIT-001) on each touch. For each touch the s has to incremented one. I just altered and used the example program "Capsense_CSD _Design".
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just remember the previous state of the CapSense button, and only increase your counter when it changes from 'not pressed' to pressed'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To add to Hli's recommendation, if you basically detect a button down,
then you also need to detect its release, then update display, and S. You
tried to do this by intoducing long delay, which is a waste of CPU MIPs and
constrains the rest of the program for other processing.
So detect down, then release, then inc S, update display. Or if you want a
button that is held down continuously keep incing S, or do so after button has
been pressed for some minimum time. This approach used to increase update
rate the longer a button down, makes button multi functional.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you boss
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Who is the "Boss" ?
To add my 2 ct:
I usually prefer a (simple) state-machine that keeps track of the required different states
-no button pressed
-button pressed
-button pressed for > 500ms (or any other time)
-button released
and the event(s) within each state that will go to another state.
To make things more complicate, you can setup a timer that interrupts at a medium rate (10 - 50Hz) and check the button when Timer expires only Frees a lot of MIPS but still maintains reactivity of the system and additionally has the opportunity to measure the time a button is pressed (or nothing did happen)
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess with the 'button released' state you really mean the 'butten released event', which is between the 'button pressed' and the 'no button pressed' states? At least thats how I would implement it...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Probably a language problem:
The button released state is a state between the button pressed state and the no button pressed state and is used to have something like a de-bouncing.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, I didn't think of using it for debouncing (but then you would need something similar for pressing the button, right?). But I think this isn't needed for CapSense, it should not have bouncing...
hli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually I need to increment the variable ‘s’ for each key press. Now I shifted the incrementing business to else braces, ie button released after a key press.
char s,s1;
LCD_Position(1u, 0u);
if (CapSense_CSD_CheckIsWidgetActive(CapSense_CSD_BUTTON0__BTN))
{s=1; // button pressed
}
else{
if(s==1){s1++; // button released
LCD_Position(1u, 1u);
LCD_PrintInt16(s1);}
s=0;}
is it OK.
Kavin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes Kevin, that looks good. But you ought to initialize s1.
By the way: It is ALWAYS advisable to use names for variables that reflect the meaning. So I would call "s1" "PressedCounter" and "s" "ButtonWasPressed" or something similar. This improves readability and can help others (us) to understand what is going on or even detect a bug.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, I just see:
You defined s1 as a aigned char, but display it on LCD with a routine that requires a 16-bit integerr. I would suggest to use for s1 an unsigned int.
Bob