Shop OBEX P1 Docs P2 Docs Learn Events
Question about code in StampWorks — Parallax Forums

Question about code in StampWorks

MichelBMichelB Posts: 154
edited 2009-11-24 17:38 in BASIC Stamp
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.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-24 17:22
    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
  • MichelBMichelB Posts: 154
    edited 2009-11-24 17:38
    Thank you Mike, well understood.
Sign In or Register to comment.