Shop OBEX P1 Docs P2 Docs Learn Events
random timer, need help — Parallax Forums

random timer, need help

mike mocentermike mocenter Posts: 4
edited 2010-05-21 02:30 in BASIC Stamp
i am in need of some help with firmware for a BS2.· I need to make a random timer to hold a pin high for a time period of 1 - 20 seconds (random) when another pin goes high.· the output will eventually play a recorded music on a sound module for a game for the random period of time.··Once the music finishes, another pin goes high.·· after that,·the timer is reset to start again.· would appreciate any help with the timer.·thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-21 02:10
    There is no timer accessible to the user. Typically this sort of thing is done by using a PAUSE statement as a clock "tick" and using a variable to hold the number of ticks passed by. You compare this to your random number and, when the number of ticks is greater than the random number, your waiting is over, like:

    ' timeLimit is the random time limit in units of 100ms

    ' If you use a time tick of 100ms, you can use bytes for the variables

    FOR timePassed = 1 to timeLimit
    PAUSE 100 ' milliseconds
    NEXT
  • mike mocentermike mocenter Posts: 4
    edited 2010-05-21 02:30
    thanks mike.· it makes sense· i do appreciate your quick response
Sign In or Register to comment.