Shop OBEX P1 Docs P2 Docs Learn Events
Function machine — Parallax Forums

Function machine

deltabossdeltaboss Posts: 10
edited 2011-02-22 08:20 in BASIC Stamp
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

Comments

  • dandreaedandreae Posts: 1,375
    edited 2011-02-22 07:23
    You can use the "DEBUG" command as a tool to test your code. You can insert the DEBUG command in sections where you expect the code to go. This will tell you if your code was excuted properly.

    Dave
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-02-22 08:20
    Sorry, but It is hard to evaluate your thoughts.

    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
Sign In or Register to comment.