Home    Worksheets    Subroutines   
 

Worksheet 109:
Stop at wall

In this worksheet you will learn how to make the buggy stop when it gets to a wall

It uses a loop which exits when the microswitch is pressed.


2)  Loop (until input...)
This loop exits when input1 (the right hand microswitch) is 1
Here is  your main program:
 
'---109 stop at wall -------------
main:
'----------start of loop---------
        do until input1=1
         gosub fwd
        loop          
'----------end of loop-----------
        let pins=%00000110  ' LEDs ON
        stop
'----------end of main program---------
                   
 
This program calls fwd every time round the loop


When input1 becomes 1 it exits the loop and
    finally lights the LEDs

It uses "gosub fwd" to go forwards a short distance. 
It uses "
until input1=1" to detect when to exit the loop.

Copy this program, and subroutine fwd from the subroutines page to Programming Editor.
Adjust fwd using values form your Buggy Journal

3) Download to your buggy and make sure it works....
when it's moving, press the right microswitch to stop it.


 
4) Subroutine park

Here's a version that can be called from a main program:

 
'---subroutine park -------------
park:
        do until input1=1
         gosub fwd
        loop          
'----------end of loop-----------
        return 
'----------end of subroutine ---------

                   

 
This subroutine calls fwd every time round the loop

When input1 is 0, it continues round the loop,
otherwise it returns to the main program

 This subroutine is not on the Subroutines page, so you'll have to come back here to reload it if you need it later.

 


 

Assessment :
Before  you've finished this worksheet, you need to show the teacher your work.

1) Keep this page on the screen with your answers filled in, so that the teacher can mark your work.

2) If you are told to, print out this page..     and hand it in for marking.

 

Content Scl Version 20/04/07