*HELP* Cool Double Digit Count Up with Pushbutton!
Hello,
I have written a somewhat simple program and wired a basic circuit that allows me to count up to 99 from zero on two seven digit displays using a pushbutton. The way I programed this I needed to use 13 of the 15 pins to control each of the individual LED's in the seven digit displays and 1 other pin to control the pushbutton state. I am trying to find out if there is a better way to program and wire this without the need of DIRH and OUTH. Maybe I could use a transistor or two but I have never used them and would need a bit of explanation. If anyone could help me please tell me how by replying. I would really appreciate it.
Also, here is the code that I used to program the BASIC Stamp.
Shane Kent
I have written a somewhat simple program and wired a basic circuit that allows me to count up to 99 from zero on two seven digit displays using a pushbutton. The way I programed this I needed to use 13 of the 15 pins to control each of the individual LED's in the seven digit displays and 1 other pin to control the pushbutton state. I am trying to find out if there is a better way to program and wire this without the need of DIRH and OUTH. Maybe I could use a transistor or two but I have never used them and would need a bit of explanation. If anyone could help me please tell me how by replying. I would really appreciate it.
Also, here is the code that I used to program the BASIC Stamp.
' {$STAMP BS2}' {$PBASIC 2.5}
' Pins 0 through 7 control the bottom, bottom left, bottom right, and decimal points.
' Pins 8 through 15 control the middle, top left, top right, and top.
' This most definiteately needs to be wired on a seperate breadboard.
left [B]VAR[/B] [B]BYTE[/B]
right [B]VAR[/B] [B]BYTE[/B]
counter [B]VAR[/B] [B]BYTE[/B]
PINNUM [B]VAR[/B] [B]NIB[/B]
time [B]CON[/B] 350
left = 0
right = 0
[B]DO[/B]
[B]IF[/B] (right = 0) [B]THEN[/B]
[B]GOSUB[/B] right0
[B]ELSEIF[/B] (right = 1) [B]THEN[/B]
[B]GOSUB[/B] right1
[B]ELSEIF[/B] (right = 2) [B]THEN[/B]
[B]GOSUB[/B] right2
[B]ELSEIF[/B] (right = 3) [B]THEN[/B]
[B]GOSUB[/B] right3
[B]ELSEIF[/B] (right = 4) [B]THEN[/B]
[B]GOSUB[/B] right4
[B]ELSEIF[/B] (right = 5) [B]THEN[/B]
[B]GOSUB[/B] right5
[B]ELSEIF[/B] (right = 6) [B]THEN[/B]
[B]GOSUB[/B] right6
[B]ELSEIF[/B] (right = 7) [B]THEN[/B]
[B]GOSUB[/B] right7
[B]ELSEIF[/B] (right = 8) [B]THEN[/B]
[B]GOSUB[/B] right8
[B]ELSEIF[/B] (right = 9) [B]THEN[/B]
[B]GOSUB[/B] right9
[B]ENDIF[/B]
[B]IF[/B] (left = 0) [B]THEN[/B]
[B]GOSUB[/B] left0
[B]ELSEIF[/B] (left = 1) [B]THEN[/B]
[B]GOSUB[/B] left1
[B]ELSEIF[/B] (left = 2) [B]THEN[/B]
[B]GOSUB[/B] left2
[B]ELSEIF[/B] (left = 3) [B]THEN[/B]
[B]GOSUB[/B] left3
[B]ELSEIF[/B] (left = 4) [B]THEN[/B]
[B]GOSUB[/B] left4
[B]ELSEIF[/B] (left = 5) [B]THEN[/B]
[B]GOSUB[/B] left5
[B]ELSEIF[/B] (left = 6) [B]THEN[/B]
[B]GOSUB[/B] left6
[B]ELSEIF[/B] (left = 7) [B]THEN[/B]
[B]GOSUB[/B] left7
[B]ELSEIF[/B] (left = 8) [B]THEN[/B]
[B]GOSUB[/B] left8
[B]ELSEIF[/B] (left = 9) [B]THEN[/B]
[B]GOSUB[/B] left9
[B]ENDIF[/B]
[B]DO[/B]
[B]LOOP[/B] [B]UNTIL[/B] ([B]IN3[/B] = 1)
[B]PAUSE[/B] 200
[B]IF[/B] (right < 9) [B]THEN[/B]
right = right + 1
[B]ELSEIF[/B] (right = 9) [B]AND[/B] (left < 9) [B]THEN[/B]
right = 0
left = left + 1
[B]ELSEIF[/B] (right = 9) [B]AND[/B] (left = 9) [B]THEN[/B]
[B]GOSUB[/B] reach99
[B]ENDIF[/B]
'IF (right < 9) THEN
' right = right + 1
'ELSEIF (right = 9) AND (left < 9) THEN
' right = 0
' left = left + 1
'ELSEIF (right = 9) AND (left = 9) THEN
' GOSUB reach99
'ENDIF
[B]LOOP[/B]
[B]right0:[/B]
[B]LOW[/B] 12
[B]HIGH[/B] 4
[B]HIGH[/B] 5
[B]HIGH[/B] 6
[B]HIGH[/B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]RETURN[/B]
[B]left4:[/B]
[B]LOW[/B] 0
[B]LOW[/B] 1
[B]LOW[/B] 10
[B]HIGH[/B] 9
[B]RETURN[/B]
[B]left5:[/B]
[B]LOW[/B] 11
[B]HIGH[/B] 1
[B]HIGH[/B] 10
[B]RETURN[/B]
[B]left6:[/B]
[B]LOW[/B] 10
[B]HIGH[/B] 0
[B]RETURN[/B]
[B]left7:[/B]
[B]LOW[/B] 0
[B]LOW[/B] 1
[B]LOW[/B] 8
[B]LOW[/B] 9
[B]HIGH[/B] 10
[B]HIGH[/B] 11
[B]RETURN[/B]
[B]left8:[/B]
[B]HIGH[/B] 0
[B]HIGH[/B] 1
[B]HIGH[/B] 8
[B]HIGH[/B] 9
[B]RETURN[/B]
[B]left9:[/B]
[B]LOW[/B] 0
[B]LOW[/B] 1
[B]RETURN[/B]
[B]reach99:[/B]
[B]FOR[/B] PINNUM = 0 [B]TO[/B] 15
[B]LOW[/B] PINNUM
[B]NEXT[/B]
[B]END[/B]
Thanks,Shane Kent

Comments
I'd do one digit on OUTL and the other on OUTH, which would use the same bit pattern for each digit. Do you want/need the decimal point to move? Could you just hardwire the DP on? That would simplify and give you 2 pushbuttons, maybe one for down and one for up.
It's available as a free .pdf download here:
http://www.parallax.com/Portals/0/Downloads/docs/books/sw/Web-SW-v2.1.pdf
You'll probably want to keep the BS2 manual handy to read the details about how some of the commands work.