2 bushbuttons one adds to display one subtracts...
rob162006
Posts: 2
Hi, im trying to make a digital display with a 7 segment counter, it starts off at 0 and if u press pushbutton 1 it will increase number by one, if u press pushbutton2 it will subtract a number, ive got the code started so that i can increase the number but my secoud pushbutton wont work at all "with the code" it is reciving a signal so i know it works though....any help would b awsome
This is what I have so far that works..,
' {$STAMP BS2}
' {$PBASIC 2.5}
Digit0 DATA %11100111
Digit1 DATA %10000100
Digit2 DATA %11010011
Digit3 DATA %11010110
Digit4 DATA %10110100
Digit5 DATA %01110110
Digit6 DATA %01110111
Digit7 DATA %11000100
Digit8 DATA %11110111
Digit9 DATA %11110110
DATaddr VAR Word ' Word variable for our pointer
counter VAR Byte ' Keep track of current digit
Dchar VAR Byte ' Variable to keep digit in
INPUT 3 ' Make pin 3 an input for the button
DIRH = %11111111 ' Make pins 8-15 outputs for the display
'
[ Program Code ]
counter=0 ' initialize counter
DATaddr = Digit0 ' Make pointer = start of data table
Main: ' Main program loop
READ DATaddr + counter, Dchar ' Read the character (byte size by default) from our marker (Digit0) + counter
OUTH = Dchar ' Send the value to port
waitkey:
IF IN3=0 THEN waitkey ' Has the button been pressed? No? try it again
PAUSE 250 ' For a little button debounce, wait 250ms
counter = counter + 1 ' increment counter
IF counter > 9 THEN counter = 0 ' limit the counter and roll it back over to zero
GOTO main
This is what I have so far that works..,
' {$STAMP BS2}
' {$PBASIC 2.5}
Digit0 DATA %11100111
Digit1 DATA %10000100
Digit2 DATA %11010011
Digit3 DATA %11010110
Digit4 DATA %10110100
Digit5 DATA %01110110
Digit6 DATA %01110111
Digit7 DATA %11000100
Digit8 DATA %11110111
Digit9 DATA %11110110
DATaddr VAR Word ' Word variable for our pointer
counter VAR Byte ' Keep track of current digit
Dchar VAR Byte ' Variable to keep digit in
INPUT 3 ' Make pin 3 an input for the button
DIRH = %11111111 ' Make pins 8-15 outputs for the display
'
[ Program Code ]
counter=0 ' initialize counter
DATaddr = Digit0 ' Make pointer = start of data table
Main: ' Main program loop
READ DATaddr + counter, Dchar ' Read the character (byte size by default) from our marker (Digit0) + counter
OUTH = Dchar ' Send the value to port
waitkey:
IF IN3=0 THEN waitkey ' Has the button been pressed? No? try it again
PAUSE 250 ' For a little button debounce, wait 250ms
counter = counter + 1 ' increment counter
IF counter > 9 THEN counter = 0 ' limit the counter and roll it back over to zero
GOTO main
Comments
Hope that helps.