Home    Worksheets    Subroutines   

Subroutine List
Click on the link to find the subroutine - or use the Next / Back buttons to scroll through    You'll have to adjust subroutines "fwd" and "rev" after copying.

 

 






Subroutine swonoff - waits for right microswitch to be pressed and released

Subroutine"swonoff" starts here This IF tests whether the right switch 
is NOT pressed Loop if not pressed Loop if not pressed Go on if it is pressed This IF tests whether the right switch 
IS pressed Loop if still pressed Loop if still pressed Subroutine SWONOFF exits here.
Flow  returns to the main  program. not pressed, so go on

BASIC:
'--This subroutine must be after the main program
'-------------------------------------------------
swonoff:
        do while input1=0  'wait till switch pressed                     
        loop 
        do while input1=1  'wait till switch released
        loop 

        return             'return to main program
'-------------------------------------------------
                      

This subroutine is explained in Worksheet 103





Subroutine fwd - moves forward a small distance in a straight line
Subroutine "fwd" starts here This output turns on both motors forwards This runs forward 1/10 second spin right or left to suit your buggy Adjust this pause to give the right amount of spin Subroutine "fwd" exits here, Both motors off BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
fwd:
        let pins=%01010000  'both motors forwards
        pause 100            'let them run
' * * * adjust these next three lines * * * 
'------
        let pins=%xxxx0000  'spin left/right
        pause x             'amount of spin
'       pause 0             ' uncomment this for half units.   
'------
        let pins=0          'stop motors
        return              'return to main program
'-------------------------------------------------

 
  

This subroutine is explained in Worksheet 104
You'll have to adjust subroutine "fwd" after copying, to suit your particular buggy



Subroutine rev - moves a small distance backwards in a straight line
Subroutine "rev" starts here This output Turns on both motors backwards This runs backward 1/10 second Left or right spin according to your buggy Pause to allow the right amount of spin Stops both motors Subroutine "rev" exits here, BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
rev:
        let pins=%10100000  'both motors  rev
        pause 100           'let them run
' * * * adjust these next three lines * * * 
'------
        let pins=%xxxx0000  'spin left/right
        pause x             'amount of spin
'       pause 0             ' uncomment this for half units.   
'------
        let pins=0          'stop motors
        return              'return to main program
'-------------------------------------------------
 
  
You'll have to adjust subroutine "rev" after copying, to suit your particular buggy



Subroutine spin180L - spins buggy 180 degrees to the left

Subroutine "spin180L" starts here This output switches on left motor backwards, right motor forwards Adjust this pause to give the right amount of spin This output box Turns off both motors Subroutine "spin180L" exits here,
BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
spin180L:
        let pins=%01100000  'left rev, right forward
        pause 2000          'let them run
        let pins=%00000000  'stop motors
        return              'return to main program
'-------------------------------------------------
 
  

The pause will need adjustment to get exactly 180 degrees, on your particular buggy
 




Subroutine flash - Turns LEDs ON then OFF
  BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
flash:
        high 1,2            'Right & left LEDs on
        pause 500           
        low 1,2             'Right & left LEDs off
        pause 500
        return              'return to main program
'-------------------------------------------------
 
  
 

 

 




Subroutine fwdb0 -moves forward a controlled distance in a straight line  
Subroutine "fwdb0" starts here call fwd subroutine to move forward a bit count down by one keep looping if count not zero Subroutine "fwdb0" exit here Subroutine "fwdb0" exits here,
with the buggy STOPPED (no motors running).
Flow  returns to the main  program. BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
fwdb0:
        do while b0>0       'loop as long as B0 isn't 0
          gosub fwd           'move forward one unit
          dec b0              'count down
        loop
        return              'return to main program
'-------------------------------------------------
 
  

This subroutine is explained in Worksheet 106




Subroutine measure -moves forward counting in b0, till it hits something.  
Subroutine "measure" starts here call fwd subroutine to move forward a bit count up by one keep looping if not touching wall Subroutine "measure" exit here start count at zero BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
measure:
        let b0=0         'start count at zero
'loop as long as *BOTH* switches are not touching a wall
        do while input1=0 and input0=0
          gosub fwd         'move forward one unit
          inc b0            'count up
        loop 
        return              'return to main program
'-------------------------------------------------
 


This subroutine is explained in Worksheet 107



Subroutine reach - moves forward counting down in b0, till the count is zero
-OR- until it hits something.
 
Subroutine "reach" starts here call fwd subroutine to move forward a bit count up by one keep looping if not touching wall Subroutine "reach" exit here start count at zero BASIC:

'--This subroutine must be after the main program
'-------------------------------------------------
reach:
' loop as long as b0 isn't 0 and  neither switch is pressed
        do while b0>0 and input1=0 and input0=0
          gosub fwd           'move forward one unit
          dec b0              'count down
        loop 
        return              'return to main program
'-------------------------------------------------
 





Content Scl Version 8/06/2007