Shop OBEX P1 Docs P2 Docs Learn Events
Can someone help with a counter for an input? — Parallax Forums

Can someone help with a counter for an input?

ArchiverArchiver Posts: 46,084
edited 2002-06-05 16:02 in General Discussion
I wrote one time and I couldn't get the code to work. I can get the
code to recognize an input but only a high or a low. How can I get
the BS2 to count inputs and then after a certain amount of time,
display something? Thanks, Chris

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-06-05 16:02
    Chris-

    Following version is a bit more fleshed out and works for me.


    Regards,

    Steve


    i VAR WORD
    counter VAR WORD
    this VAR BIT
    last VAR BIT

    HIGH 4
    HIGH 5

    again:
    counter = 0
    FOR i = 0 TO 5000 ' adjust to desired interval
    this = IN0
    counter = this ^ last * (1 - this) + counter
    last = this
    NEXT

    DEBUG CR, HEX4 OUTS, " ", DEC counter
    OUT4 = ~( counter / 3 MAX 1 )
    OUT5 = ~( counter / 4 MAX 1 )
    GOTO again


    christopher41877 wrote:

    > I wrote one time and I couldn't get the code to work. I can get the
    > code to recognize an input but only a high or a low. How can I get
    > the BS2 to count inputs and then after a certain amount of time,
    > display something? Thanks, Chris
Sign In or Register to comment.