Shop OBEX P1 Docs P2 Docs Learn Events
2 bushbuttons one adds to display one subtracts... — Parallax Forums

2 bushbuttons one adds to display one subtracts...

rob162006rob162006 Posts: 2
edited 2011-02-20 11:03 in Learn with BlocklyProp
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

Comments

  • eod_punkeod_punk Posts: 146
    edited 2011-02-20 09:30
    Your only addressing the first button in your waitkey code.
    waitkey:
      IF PshBtn1 AND PshBtn2=0 THEN waitkey
      IF PshBtn1=1 THEN counter=counter+1
      IF PshBtn2=1 THEN counter=counter-1
      PAUSE 250 ' For a little button debounce, wait 250ms
      IF counter = 10 THEN counter = 0 ' limit the counter and roll it back over to zero
      IF counter = 255 THEN counter = 9 ' If you subtract from zero display will go to 9
      GOTO main 
    

    Hope that helps.
  • rob162006rob162006 Posts: 2
    edited 2011-02-20 11:03
    thanks thats exactally what it needed
Sign In or Register to comment.