Function machine
deltaboss
Posts: 10
I recently did a function machine in school and used the BS2 I would like some help on which program was better
The Question is at THE BOTTOM of the post most of this is just code. If anyone could help I would be very grateful.
1st
' {$STAMP BS2}
' {$PBASIC 2.5}
value VAR Word
index VAR Word
OUTH = %00000000
DIRH = %11111111
value = 0
OUTH= %00011000
DO
IF IN3 = 1 THEN
GOSUB display
ENDIF
LOOP
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
RETURN
ENDIF
LOOP
finale:
FOR value = 1 TO 5
OUTH= %00000000
PAUSE 300
OUTH= %11111111
PAUSE 300
NEXT
value = 0
OUTH = %00011000
RETURN
the second one is this
' {$STAMP BS2}
' {$PBASIC 2.5}
value VAR Word
index VAR Word
OUTH = %00000000
DIRH = %11111111
value = 0
OUTH= %00011000
DO
IF IN3 = 1 THEN
GOSUB display
ENDIF
LOOP
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
ENDIF
RETURN
LOOP
finale:
FOR value = 1 TO 5
OUTH= %00000000
PAUSE 300
OUTH= %11111111
PAUSE 300
NEXT
value = 0
OUTH = %00011000
RETURN
the difference was this segment of code
num 1
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
RETURN
ENDIF
LOOP
program 2
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
ENDIF
RETURN
LOOP
the retun was placed at different parts. the first one worked but the second wasn't tested, out of curiosity, would num 2 work or does the return have to be before the endif
The Question is at THE BOTTOM of the post most of this is just code. If anyone could help I would be very grateful.
1st
' {$STAMP BS2}
' {$PBASIC 2.5}
value VAR Word
index VAR Word
OUTH = %00000000
DIRH = %11111111
value = 0
OUTH= %00011000
DO
IF IN3 = 1 THEN
GOSUB display
ENDIF
LOOP
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
RETURN
ENDIF
LOOP
finale:
FOR value = 1 TO 5
OUTH= %00000000
PAUSE 300
OUTH= %11111111
PAUSE 300
NEXT
value = 0
OUTH = %00011000
RETURN
the second one is this
' {$STAMP BS2}
' {$PBASIC 2.5}
value VAR Word
index VAR Word
OUTH = %00000000
DIRH = %11111111
value = 0
OUTH= %00011000
DO
IF IN3 = 1 THEN
GOSUB display
ENDIF
LOOP
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
ENDIF
RETURN
LOOP
finale:
FOR value = 1 TO 5
OUTH= %00000000
PAUSE 300
OUTH= %11111111
PAUSE 300
NEXT
value = 0
OUTH = %00011000
RETURN
the difference was this segment of code
num 1
display:
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
RETURN
ENDIF
LOOP
program 2
OUTH= %00000000
LOOKUP value,[ %00110000, %01001000, %01100000, %01111000, %10010000, %10101000,%11000000,%11011000,%11110000] , index
OUTH = index
Value = value + 1
IF value = 10 THEN
GOSUB finale
ENDIF
DO
IF IN3 = 0 THEN
ENDIF
RETURN
LOOP
the retun was placed at different parts. the first one worked but the second wasn't tested, out of curiosity, would num 2 work or does the return have to be before the endif
Comments
Dave
Ask your teacher to give you a lesson on
1. Stating the purpose / function of your code
2. Documenting / commenting your code
3. Debugging / stepping thru your code