How to increment the value of a 7-seg LED after IN1 goes HIGH
jmerrell
Posts: 25
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
' {$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
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: