Home    Worksheets    Subroutines   
 

Worksheet 110:
Spins and other states

In this worksheet you will learn how much delay is needed to  make the buggy
move distances and spin the angles you want

1) Start up the PICAXE Programming Editor program:  click here
  - Make sure that the following options are selected (in View / Options...)
  -
PICAXE-18x   (Mode tab)
  - Text-mode Colour syntax   (Editor tab)
  - Compiler-Enhanced   (Editor tab)
(if these aren't set correctly you won't be able to simulate)

  - You should see the BASIC page. (if not, Click the Basic button.. )

2)  A single state:
This is one of the simplest programs.
Here is  your main program:
 
'---A simple state --------------------

main:
        gosub swonoff        ' wait for right switch
'----start of state
        let pins=%01010000   ' start motors
        pause 1000           ' wait 1 second
'----end of state

        let pins=0           ' stop motors
        stop                 ' stop picaxe chip

'----------end of main program---
                   
 
This program starts by turning the motors on


It then waits 1 second before turning them off

It uses "let pins=%01010000" to switch the motors on. 
It uses "pause 1000" to let them run for 1 second.
 

3) Download to your buggy and see the effect....
How far does the buggy go in 1 second?.
Put the buggy on a piece of paper.
Mark where the front is with a pen, and then run the program.
When the buggy stops, make another mark.  Measure the distance between the marks.
My Buggy travels at mm per second.

The time taken to travel 100 mm is therefore  (100 / speed (mm/s))

 You should now work out the pause value needed for 100mm. - (You might need this later)
Record this in the "Speed" section of your Buggy Journal.

4)  3 states in a row:
This is more complex programs.
Here is  your main program:
 
'---Three states -------------

main:
'----start of state 1
        let pins=%01010000  ' start motors forwards
        pause 2000          ' wait 2 seconds
'----end of state 1

'----start of state 2
        let pins=%10010000  ' start motors spinning
        pause 1300          ' wait 1.3 seconds
'----end of state 2

'----start of state 3
        let pins=%10100000  ' start motors
        pause 2000          ' wait 2 seconds
'----end of state 3

        let pins=0          ' stop motors
        stop                ' stop picaxe chip

'----------end of main program---

                   

   

The first state moves it forwards

 

The second state
   does a spin

 

The third state
   moves it backwards

It uses "let pins=%XXXX0000" to switch the motors on. 
It uses "pause YYYY" to let them run for the right amount of time to complete the movement.
A "let pins=0"  is needed to switch the motors off at the end
 

5) Spin180L
This subroutine has a single state in it which spins the buggy round to face the other way.
Importantly, it then stops the motors.

There is a subroutine for this on the subroutines page.

Download this to your buggy.
Test how much it spins with the value give.
Then adjust the pause value so that it spins exactly 180 degrees
 - keep downloading new values till you get it right.

Record the pause value for spin180L
in the Spin180L section of your Buggy Journal.

(You will need this later)

Calculate the pause value to make the buggy spin 90 degrees.
Record this in your
Buggy Journal.


 

Assessment :
Before  you've finished this worksheet, you need to show the teacher your work.
Make sure You've filled in your buggy Journal.


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 22/4/07