It uses
"letb0=0" to start the loop with a count of zero. It uses
"untilb0=10" to
control when the loop finishes. It uses
"incb0" to step the count up by 1 each time you go round the loop.

This loop does not go on forever. It stops when the count
reaches 10.

3) Simulate the loop.

Click on Simulate/Stepon the menu bar.

The Simulator is ready to run the program, but won't do anything
until you tell it to step to the next basic command.
Switch on the "Show variables" part of the simulate screen.

There should be a Simulate window on the PC screen like this:

Step round the program.

Use
the step button
Each line will be highlighted as it briefly runs.

Step on till you get
to the first
"do"
What is the value of b0 the first time you get to the "do" command
Now watch the variable b0 increase each time it passes the line
"incb0" in the
program
Finally check that it goes to line "let
pins=%00000110"
when the count is high enough.
What is the value of b0 when you get to line "let
pins=%00000110"

4)
Variables.

In the simulator
there is a display of all 14 variables:
these are called b0 to b13.
In the loop above we only use b0.We could have used any of the other 13.
Some facts:

Variables store
numbers, the smallest is 0, the largest is 255.

You can do maths with variables - add numbers to variables or subtract themadd 2 variables togethermultiply and divide variables or numbers.

You can use a variable's value to control a decision
e.g. "if b0=99"

All variables are set to zero when the program starts.

5) Questions on
variables

(You might like to use the
let simulator to help you
with some
of these... )

What do the following "let" commands do:inc b0
let b0=b0-1 let b1=b0*2 let b0=b0/2 Variables:
How many variables are there in a Picaxe What's the value of b0 when you first switch on?

When You've worked out the answers,
fill in the "Picaxe Maths" section of your Buggy Journal.

6) Over to you to make
it do something useful...

Write a program to call
"fwd" 30 times using a count-up loop.
Use subroutine "swonoff" to wait for the right microswitch before you start.
You'll need to fetch "swonoff" and "fwd"
from the subroutines page.Put these subroutines at the very bottom of your program.

It
should exit the loop when b0=30
Inside the loop,
it should call fwd
it should count up using b0

After the loop
exits, it lights the LEDs

7) Download to your buggy and use it to measure....How far the buggy goes with 30 calls to fwd.

Run the buggy on a piece of paper.
Line up the back with the end of the paper,
and then start the program.When the buggy stops, mark the new position of the back of the buggy.
Measure
the distance travelled with a ruler.
Distance travelled by 30 calls to subroutine "fwd"=mm.

( You can calculate the next 2 if you like - or you can measure the distances by adjusting your program. )How far does the buggy go with 10 calls to fwd?=mm.How far does the buggy go with 1 call to fwd? =mm.

8) Make the buggy move across the baseboard
and not bump into the wallWith what you now know, calculate the number of loops needed to
cross the baseboard
- from Bay2 to Bay1.
(It is 655 mm across)
-
Or if you prefer, sideways aiming towards Bay3 (it's 855mm in that
direction)Modify the program to stop
Just before it reaches the other side. Record this in you journal and in the box below. Number of "fwd" loops to cross the baseboard
Bay2-Bay1 loops

Assessment : You should already be producing a Report as part of the
assessment for the
Baseboard
Task.

1) Explain how you've used this sheet, and which part of the task it's
helped you with.