Shop OBEX P1 Docs P2 Docs Learn Events
How to increment the value of a 7-seg LED after IN1 goes HIGH — Parallax Forums

How to increment the value of a 7-seg LED after IN1 goes HIGH

jmerrelljmerrell Posts: 25
edited 2013-11-18 06:34 in BASIC Stamp
Does anyone know the code to increment the value (0-3) of a 7-segment LED after IN1 goes high? Similar to a momentary switch...ON then OFF. I am using the 7-segment LED as a score for a game. I am using lookup/lookdown in my program but cannot get it to work. Only a "1" displays after IN1=1 and does not change after subsequent highs. Suggestions greatly appreciated. Thanks

' {$STAMP BS2}
' {$PBASIC 2.5}
'========DIR===========================================
OUTH = %00000000
DIRH = %11111111
'=======VARIABLES======================================
SRVOcounter VAR Word
SCORcounter VAR Bit
index VAR Bit
'=======MAIN===========================================
MAIN:
DO
SCORcounter = 0
IF IN1 = 1 THEN
FREQOUT 6, 140, 4200
GOSUB TARGET1
ELSEIF IN2 = 1 THEN
FREQOUT 6, 140, 4200
GOSUB TARGET2
ENDIF
IF SCORcounter = 3 THEN
END
ENDIF
LOOP
'========SUBROUTINES====================================
Target1:
LOOKDOWN SCORcounter, [ 3, 2, 1], index
LOOKUP index, [ %10000100, %11010011, %11010110], OUTH
SCORcounter = SCORcounter + 1
PAUSE 20
FOR SRVOcounter = 1 TO 25
PULSOUT 14,1100 'Servo rotates DOWN"
PAUSE 20
NEXT
FOR SRVOcounter = 1 TO 25
PULSOUT 14, 660 'Servo rotates UP"
PAUSE 20
NEXT
PAUSE 20
RETURN
Target2:
LOOKDOWN SCORcounter, [ 3, 2, 1], index
LOOKUP index, [ %10000100, %11010011, %11010110], OUTH
SCORcounter = SCORcounter + 1
PAUSE 20
FOR SRVOcounter = 1 TO 25
PULSOUT 15,1100 'Servo rotates DOWN"
PAUSE 20
NEXT
FOR SRVOcounter = 1 TO 25
PULSOUT 15, 660 'Servo rotates UP"
PAUSE 20
NEXT
PAUSE 20
RETURN
RETURN

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,560
    edited 2013-11-18 06:34
    A few things I see...

    1) Adjust your VAR declaration for SCORcounter to a BYTE rather than a BIT
    2) Move the line that says "SCORcounter = 0" so that it happens before the DO
    3) Since Target #1 and Target #2 are specific values anyway, you can do away with the LOOKUP and LOOKDOWN and just hard code it. For that matter SCORcounter can be hard coded also.

    Example:
    Target1:
    OUTH = %11010110
    SCORcounter = 1
    
Sign In or Register to comment.