Shop OBEX P1 Docs P2 Docs Learn Events
Single-digit counter — Parallax Forums

Single-digit counter

TMBTMB Posts: 2
edited 2011-02-10 04:13 in BASIC Stamp
Hi,

I'm new to pbasic, and I'm trying to make a single-digit counter which counts as long as you hold a button pressed, and then stops counting and displays the number the count is at when you release the button.

This is what I got so far:
' {$STAMP BS2}
' {$PBASIC 2.5}

Segs      VAR OUTL
SegsDirs  VAR DIRL
Button     VAR IN8

idx       VAR Nib

Digit0    DATA  %00111111
Digit1    DATA  %00000110
Digit2    DATA  %01011011
Digit3    DATA  %01001111
Digit4    DATA  %01100110
Digit5    DATA  %01101101
Digit6    DATA  %01111101
Digit7    DATA  %00000111
Digit8    DATA  %01111111
Digit9    DATA  %01100111

Reset:
  SegsDirs = %01111111

Main:
 IF Button = 1 THEN
    FOR idx = 0 TO 9
      READ (Digit0 + idx), Segs
      PAUSE 25
    NEXT
 ENDIF
GOTO Main

But whenever i release the button, it stops at the number 9 no matter what :S

Can someone help? :)

Comments

  • Clive WakehamClive Wakeham Posts: 152
    edited 2011-02-10 03:40
    The problem is that you have the check for the button held down before the counting loop so that it will only check for the button once, and then run through the loop up to 9 before checking again.
    You need to put a command that checks the button status within the "for next" loop.
  • TMBTMB Posts: 2
    edited 2011-02-10 04:13
    It worked, thank you :)
Sign In or Register to comment.