
4. Now change the program so that it is the same as below. It is just the same as above but
modified with an
if
/
else
/
end
if
statement (to set up two possible paths for the program to
follow):
symbol
P0 = B.0
' Define Output P0
symbol
IN1 = pinB.1
' Define Input P1
do
' Do the following ...
if
IN1 = 1
then
' When the slide switch is a 1 ...
high
P0
' Set P0 high (5V)
pause
200
' Keep P0 high for 200ms
low
P0
' Set P0 low (0V)
pause
200
' Keep P0 low for 200ms
else
' Otherwise ( slide switch is a 0 ) ...
high
P0
' Set P0 high (5V)
pause
2000
' Keep P0 high for 2000ms (2s)
low
P0
' Set P0 low (0V)
pause
2000
' Keep P0 low for 2000ms (2s)
end if
loop
' Repeat this loop forever
Some things to note about the program above:
•
The module at Pin 1 accepts input from the user and so it is referred to as IN1. This tells
the microcontroller to expect input at this pin. We also add the
symbol
definition for IN1 at
the top of the program.
5. Save your program as
SlideSwitchprogram.bas
6. Press the F5 key ( or use the PICAXE/Program menu option ) to download your program into
the PICAXE on your Versabot motherboard. A Syntax Check is automatically performed
before downloading so it isn’t necessary to press the F4 key ( or use the PICAXE/Syntax
Check menu option ) before starting a download, but you can press F4 to check the syntax
before downloading if you wish.
7. Once the downloading has completed you can switch the slide switch back and forth to see
the difference in the LED flashing speeds.
8. The program downloaded completely replaces the previous program in the Versabot PICAXE
and it will be remembered even while the Versabot is turned off. The Versabot PICAXE always
remembers the last program downloaded to it, and only the last program downloaded.
Summary of Contents for Versabot
Page 1: ...The Versabot Manual July 2009...
Page 23: ...Step 03 Step 04 Step 05...
Page 24: ...Step 06 Step 07 Step 08...
Page 25: ...Step 09 Step 10 Step 11...
Page 26: ...Step 12 Step 13...