View Full Version : Question about code in StampWorks
11-25-2009, 01:03 AM
SW21-EX14-Debounce.BS2 and SW21-EX14-Debounce-Adv.BS2 Subroutines, "FOR idx = 1 TO 5", Why 1 TO 5?
I don't understand from where come 1 and 5, thank you for help.
11-25-2009, 01:22 AM
On page 96:
The purpose of Get_Buttons is to ensure that the inputs stay pressed for at least 25 milliseconds with no contact “bouncing.” Debounced inputs will be returned in the variable, btns, with a valid input represented by a “1” in the respective button position.
Notice in the code that there's a PAUSE for 5ms. Notice that 5ms x 5 times = 25ms. The FOR loop provides the 5 times.
You could change the PAUSE time or the number of times through the loop and the code would still work as long as the total time is on the order of 25ms to maybe 50ms.
Here's a nice article on debouncing: www.ganssle.com/debouncing.pdf (http://www.ganssle.com/debouncing.pdf)
11-25-2009, 01:38 AM
Thank you Mike, well understood.