Shop OBEX P1 Docs P2 Docs Learn Events
New to programming and need a little help. — Parallax Forums

New to programming and need a little help.

SpardaSparda Posts: 5
edited 2007-11-05 16:05 in BASIC Stamp
I'm trying to get this program to cycle through each subroutine, but I can't figure out what I'm doing wrong. Any advice?

' {$STAMP BS2}
' {$PBASIC 2.5}

DEBUG "Program Running!"

'
[noparse][[/noparse] Variables ]

counter VAR Nib ' Counts alternate contacts.
old15 VAR Bit ' Stores previous IN15.
old0 VAR Bit ' Stores previous IN0.


'
[noparse][[/noparse] Initialization ]

FREQOUT 4, 2000, 3000
counter = 1 ' Start alternate count.
old15 = 0 ' Make up old values.
old0 = 1

'
[noparse][[/noparse] Main Routine ]

DO

IF (IN15 <> IN0) THEN
IF (old15 <> IN15) AND (old0 <> IN0) THEN
counter = counter + 1
old15 = IN15
old0 = IN0
IF (counter > 4) THEN
counter = 1
GOSUB Stay_Still
ENDIF
ELSE
counter = 1
ENDIF

ENDIF


IF (IN0 = 0) AND (IN15 = 0) THEN
GOSUB Stay_Still
GOSUB Forward_Pulse
GOSUB Turn_Right
GOSUB Forward_Pulse
GOSUB Stay_Still
GOSUB Turn_Around
ELSEIF (IN0 = 0) AND (IN15 = 1) THEN
GOSUB Turn_Circle
GOSUB Stay_Still
ELSEIF (IN15 = 0) THEN
GOSUB Photoresistors
ELSE
GOSUB Stay_Still
ENDIF

LOOP

'
[noparse][[/noparse] Subroutines ]
Stay_Still:
FOR counter = 1 TO 20
PULSOUT 12, 750
PAUSE 20
NEXT

Forward_Pulse:
FOR counter = 1 TO 389
PULSOUT 13, 890
PULSOUT 12, 625
PAUSE 20
NEXT
RETURN

Turn_Around:
FOR counter = 1 TO 87
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Turn_Circle:
FOR counter = 1 TO 1250
PULSOUT 13, 850
PULSOUT 12, 717
PAUSE 20
NEXT
RETURN

Turn_Right:
FOR counter = 1 TO 42
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Photoresistors:
IF (IN14 = 0) AND (IN1 = 0) THEN
PULSOUT 12, 750
ELSEIF (IN14 = 0) AND (IN1 = 1) THEN
HIGH 8
LOW 7
PAUSE 20
RETURN
ELSEIF (IN1 = 0) AND (IN14 = 1) THEN
HIGH 7
LOW 8
PAUSE 20
RETURN
ELSE
LOW 7
LOW 8

ENDIF
RETURN

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-05 14:36
    So what is the program actually doing? What happens if you put DEBUG statements in each subroutine to show what's called? What happens if you put DEBUG statements after each IF, ELSEIF, and ELSE?
  • SpardaSparda Posts: 5
    edited 2007-11-05 14:39
    Well, the first routine is supposed to make my BoeBot go forward five feet, stop, go backwards 5 ft., and do a 360 turn. The second one is to make it go in a circle with a diameter of 4 ft and have it stop close to where it started. Finally, the red LEDs are supposed to turn on when the corresponding photoresistors are covered.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-11-05 14:44
    I notice the Stay_Still sub routine does not have a RETURN statement.

    Jeff T.
  • SpardaSparda Posts: 5
    edited 2007-11-05 14:45
    I had one, but all my BoeBot did was stay still so I thought that the RETURN statement was making it go back to the same point.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-11-05 14:51
    I also notice counter is declared a nib when farther down you are using it to count to 1250, 1250 needs a word variable.

    Jeff T.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-05 14:52
    Sparda,
    I wasn't asking what you intend the program to do. I was prodding you to find out what's actually happening. That's how you debug. You find out by "direct evidence" (if you can) what is actually happening and you compare that to what you think should be happening to figure out either the error in your logic or some mistake in implementing what you thought you were doing or ... whatever.
  • SpardaSparda Posts: 5
    edited 2007-11-05 14:53
    Anything else?



    Oh, the program isn't responding at all and I haven't tried those yet.

    Post Edited (Sparda) : 11/5/2007 3:57:42 PM GMT
  • SpardaSparda Posts: 5
    edited 2007-11-05 15:57
    Tried the DEBUG statements and still nothing. How would I make it so that the left whisker triggers a new subroutine? I thought it was just IN0 = 0 and then the subroutines, but I'm not too sure.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-05 16:05
    You really need to start at the beginning of your program and proceed statement by statement through it making sure that each decision works as you expect. For example, does your program finish its initialization? Does the first IF statement succeed when the two inputs (0 and 15) are different? Use the DEBUG statement to give you information.
Sign In or Register to comment.