Home    Worksheets    Subroutines   

Worksheet 102:
Buggy Inputs
 

In this worksheet you will learn which input each of the two microswitches is connected to.

You'll also learn how to make a microswitch control the buggy.

1) Start up the PICAXE Programming Editor program:  click here
  - Make sure that PICAXE-18x is selected (in View / Options...)
  - You should see the BASIC page. (if not, Click the Basic button.. )

2) Enter the following BASIC program in Programming Editor:      
 
'--------------------------------------
       do
       let b0=input0 ' read input 0 
       let b1=input1 ' read input 1
       let b2=input2 ' read input 2
       let b6=input6 ' read input 6
       let b7=input7 ' read input 7
       debug         ' display on PC
       loop          ' go to start
'--------------------------------------
 
 
This program copies the values of all 5 inputs (0,1,2,6&7) to
the internal variables. (b0, b1, b2, b6, b7)

It then uses the "debug" command to display them on the PC screen.


3) Download the program to the buggy:
  - connect up the download lead to the socket at the back of the buggy.
  - switch on the buggy,
  - Click on PICAXE/Run or click the button. (or use F5)


The PIC chip is now running the program, but won't be moving.
Check that there is a Debug window on the PC screen like this:
 

 

 

 


4) The PicAxe chip has 5 inputs.
They are called input0,input1,input2,input6 & input7.
Find out which microswitch you have to press to make them 1 (or ON)                     

Fill out the following table by running the program above
and checking which of b0 - b7 become 1 when you press each switch:

Input

Variable

Function

input0

b0

input1

b1

input2

b2

input3

 

<There is no Input 3 >

input4

 

<There is no Input 4 >

input5

 

<There is no Input 5 >

input6

b6

input7

b7

  When You've worked out what each input does, fill in the
 "Buggy Inputs" section of your Buggy Journal.


 

5) REVISION: Remember what the different patterns of outputs do.                      

Fill out the following table by referring back to your notes from Worksheet 1:

Let pins=

Function

%00000001

%00000010

%00000100

%00001000

%00010000

%00100000

%01000000

%10000000

Remember: to run two or more outputs together you add together the separate patterns.


 

So far you've used a simple loop that reads the inputs.

6) Now write a Basic program with a decision
(This is very like the program for the Lighthouse in Flowol).

A decision in Basic is an "if" statement.
There's a decision inside the loop so that different output commands are used depending on whether the switch is pressed or not.


Below is the structure of the program:

You have to fill in the input number (to choose which microswitch controls the buggy),
and the two output patterns (to control what the buggy does)

 

'--------------------------------------------
main:   if input?=1 then pressed ' decision

'--------------------------------------------
nopress: let pins=%XXXXXXXX     ' set outputs 
         goto main              ' go to start

'--------------------------------------------
pressed: let pins=%YYYYYYYY     ' set outputs 
         goto main              ' go to start
'---------------------------------------------
 
This program sets the pattern of Outputs according to whether the microswitch is pressed or not:

Replace input? with the input
(input1 or input2 etc) that your chosen microswitch is connected to.

Set XXXXXXXX and YYYYYYYY to be the patterns that make the buggy move or flash how you want.

 Look back to the revision table above, for how to control the two motors and light the LEDs.

You choose whether to flash the lights or to move the wheels (or even both!).
 


 

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