Shop OBEX P1 Docs P2 Docs Learn Events
stopwatch — Parallax Forums

stopwatch

vla7vla7 Posts: 79
edited 2011-01-23 08:53 in BASIC Stamp
I am building a lap timer for a radio control car track. It will basically consist of an IR emitter and receiver. Every time the car passes where the emitter and receiver line up it will block the signal therefore changing the state of the receiver. Is there a way to have the basic stamp keep track in seconds how long it takes the receiver to go from a 1 to 0 to a 1 again (therefore the car having completed one lap). I'm not concerned about precision more than I am concerned with consistency. In fact I could live with it being a few seconds off so long that it is consistent.

Thank You, any help would be greatly appreciated.

vla7

Comments

  • Qwaszx72Qwaszx72 Posts: 30
    edited 2011-01-23 08:37
    counter var word
    counter = 0
    do
    pause 950
    counter = counter + 1
    loop until in0 = 1

    debug "It took ", dec counter, " seconds for the Boe-Bot to complete one lap."
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-23 08:53
    The problem with Qwaszx72's suggestion is that the Stamp will miss the car going through the sensor because the Stamp is waiting in the PAUSE for most of a second. That's the right idea though. Say that the car will block the sensor for at least 1/20th of a second. (There are ways to stretch that out if needed using a resistor and capacitor.)
    seconds var word
    ticks var byte
    start:
    seconds = 0
    do
    for ticks = 1 to 20   ' this loop should take about a second
    if in0 = 0 then goto lap   ' check for car passing lap
    pause 50  ' wait for 50ms
    next
    seconds = seconds + 1   ' we've finished one second
    loop
    
    lap:
    debug "It took ",dec seconds," for the last lap",cr
    goto start
    
Sign In or Register to comment.