How to Detect Longpress and Shortpress buttons in Atxmega256a3bu xplained board?. Can anyone help me with it?
Tell and show us what you have done so far, and explain where you are stuck.
Click Link: Get Free Stock: Retire early! PM for strategy
Post your code that doesn't work. If you don't have any code, post your ideas on an algorithm that would solve the problem.
the general idea is that when a keypress is detected, you start a timer, after timer overflow if it still pressed . . its a longpress
however if you stuck somewhere, just post your idead - work so far - code as already mention by
Set a timer interrupt to fire every 1ms or so.
Inside the ISR:
If the button is pressed, increase a counter.
When the button isn't pressed and the counter isn't zero, see how high it is to find out how long the button was pressed.
Set the respective flag(volatile!) and reset the counter.
Outside of the ISR, do what ever needs to be done and reset the flag.
If you set the threshold for a short press at more than one (e.g. five to ten), you get debouncing.
"Some people die at 25 and aren't buried until 75." -Benjamin Franklin
What is life's greatest illusion?" "Innocence, my brother." -Skyrim
static void my_callback(void);
static void my_callback()
if(TCC0.CNT == 624)
// User code to execute when the overflow occurs here
//Important to clear Interrupt Flag
i have written this code currently to just turn off the led if the count is 624, but the program seems to get stuck in while loop.Is the idea correct?
TCC0.CNT is not going to be 624 in the overflow callback, it's reset to 0 before that (and with fast enough clocking it could already be > 0).
EDIT: btw, why check anyway? You already know there was an overflow, this is the overflow callback after all.
© 2018 Microchip Technology Inc.