Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. goto main_loop # Run the main loop when the script starts (see below).
  2.  
  3. # This subroutine returns 1 if the button is pressed, 0 otherwise.
  4. # To convert the input value (0-1023) to a digital value (0 or 1) representing
  5. # the state of the button, we make a comparison to an arbitrary threshold (500).
  6. # This subroutine puts a logical value of 1 or a 0 on the stack, depending
  7. # on whether the button is pressed or not.
  8. sub button
  9. 2 get_position 500 less_than
  10. return
  11.  
  12. # This subroutine uses the BUTTON subroutine above to wait for a button press,
  13. # including a small delay to eliminate noise or bounces on the input.
  14. sub wait_for_button_press
  15. wait_for_button_open_10ms
  16. wait_for_button_closed_10ms
  17. return
  18.  
  19. # Wait for the button to be NOT pressed for at least 10 ms.
  20. sub wait_for_button_open_10ms
  21. get_ms # put the current time on the stack
  22. begin
  23. # reset the time on the stack if it is pressed
  24. button
  25. if
  26. drop get_ms
  27. else
  28. get_ms over minus 10 greater_than
  29. if drop return endif
  30. endif
  31. repeat
  32.  
  33. # Wait for the button to be pressed for at least 10 ms.
  34. sub wait_for_button_closed_10ms
  35. get_ms
  36. begin
  37. # reset the time on the stack if it is not pressed
  38. button
  39. if
  40. get_ms over minus 10 greater_than
  41. if drop return endif
  42. else
  43. drop get_ms
  44. endif
  45. repeat
  46.  
  47. # An example of how to use wait_for_button_press is shown below:
  48.  
  49. # Uses WAIT_FOR_BUTTON_PRESS to allow a user to step through
  50. # a sequence of positions on servo 1.
  51. main_loop:
  52. begin
  53. 4000 frame
  54. 5000 frame
  55. 6000 frame
  56. 7000 frame
  57. 8000 frame
  58. repeat
  59.  
  60. sub frame
  61. wait_for_button_press
  62. 1 servo
  63. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement