Shop OBEX P1 Docs P2 Docs Learn Events
As usual need Help — Parallax Forums

As usual need Help

GuidoGuido Posts: 195
edited 2005-11-19 18:21 in BASIC Stamp
I am having difficuilty in trying to come up with an idea for counting contact closures in a 10 second window. The results of the calculation will have four different goto statements. The program would wait for the first contact closure and monitor and count·for ten seconds....Any Ideas?
Thank You
Guido

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-09-25 10:49
    Guido -

    At the possible risk of sounding all too obvious, you may want to take a look at the COUNT command. I suspect that will do exactly what you want, although you may have to extend the time frame a bit.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-25 21:37
    If you're using a BS2 or BS2e the timing for COUNT is in milliseconds, so you could do this (assuming active-low input):

    · DO : LOOP UNTIL (Trigger = 0)···· ' wait for first press
    · DO : LOOP UNTIL (Trigger = 1)···· '·force release
    · COUNT Trigger, 10000, presses··· ·' count other presses

    You'll have to adjust the timing parameter for other modules

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-26 14:20
    Note if you're really counting "switches", you'll need to 'debounce' your inputs.
  • GuidoGuido Posts: 195
    edited 2005-11-19 18:21
    Jon,

    Thank you for your response. Reading about the Count statement, I am worried that the final count might not be accurate. The reason I am saying this, my count will be triggered by a momentary contact closuser anywhere from .5 to 3 seconds apart. Also the first count will be initialized in the main program, which will then goto your example loop program:

    ·DO : LOOP UNTIL (Trigger = 0)···· ' wait for first press
    ·DO : LOOP UNTIL (Trigger = 1)···· '·force release
    ·COUNT Trigger, 10000, presses··· ·' count other presses



    I assume I could just add +1 to the Count trigger statement. but how would I initialailize the Trigger=0 Loop and start the timer if that would be the only contact closuser....

    Thank You

    Guido

Sign In or Register to comment.