Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Controlling
ARC, ALERT and VLL lights using NQC.
Assumed Knowledge:
THe Basics, My
first program, Using Include
Written By: BILL LANE
BACK
In all the supplied missions for the Spybots the arc lights
and the alert light are regularly used to provide mission
information. They tell us how much time remains, how close
we are to achieving the goal, if the enemy is near, etc, etc.
In other words they are our robots main communication tool.
As such it is important that we can take control of these
lights and make them work for us.
Controlling the LED's involves using LED[mode].
You can find the different modes defined in spybot.h
if you want to have a look. As such you'll need to include
this file at the top of your script before defining the main
command block (if this doesn't make any sense go have a look
at Using Include and then come back).
Using LED requires that
you supply two pieces of information (referred to as parameters);
the mode and a value relevant for that mode. The first mode
we'll consider is iDisplay
(there are 16 modes in all and you'll find them all defined
in spybot.h). It will turn the red and green arc lights on,
if we tell it which ones we want turned on. We do that by
sending it a value. For example if we send cRed1
it will turn on the first red light. Note that the lights
are numbered from the outside in. With cRed1
and cGreen1 on the outside
and cRed3 and cGreen3
in the middle. If we send it two or more values joined
by a + sign we can turn
on multiple lamps. Here's an example:
program lightingUp
{
#include<spybot.h>
main{
LED[iDisplay] = cRed1 + cGreen1
wait 200
}
}
Once again we're using Wait
so we can actually see a result. When you run that
you should see the two outside arc lights come on for 2 seconds.
Armed with that information let's have a look at another
mode. If we want the lights to blink we can use iDisplayBlink.
For values we either tell it which lights to blink or send
it 0 to stop blinking. Before we look at the code let's look
at iDisplayBlinkInterval.
We use this to tell the Spybot how long the blink should last.
The value represents the duration in 100ths of a second. So
let's see an example:
LED[iDisplayBlinkInterval] = 50
LED[iDisplayBlink] = cRed1 + cGreen1
wait 100
N.B. The Spybot has a
default blink rate. But if you change the duration using this
mode it will retain that blink rate until you change it in
code or restart the Spybot.
In this example, the two outside lights will go on and off
twice before the program ends. With that knowledge under your
belt you might want to experiment with creating your own light
sequences before we move on.
The next series of modes we'll look at are those involving
the ALERT light. They are: iYellowWarn,
iYellowBlink, iYellowBlinkInterval
and they work in a very similar fashion the first three we
discussed. The biggest difference being that with only one
alert light we can turn it on using 1 and off using 0. The
following example turns tells the alert light to blink for
1 second:
LED[iYellowBlinkInterval]
= 20
LED[iYellowBlink] = 1
wait 100
Add the following code and it will stay on for another second
without blinking before turning off completely:
LED[iYellowBlink]
= 0
LED[iYellowWarn] = 1
wait 100
We can also use this command to control the VLL ( the laser
) light in a very similar way. The relevant modes are;
iVLL, iVLLBlink,
iVLLBlinkInterval. There
is one big difference here. If you don't expressly turn off
the VLL it will remain on after the program ends. The other
issue is that it's not enough just to tell it to stop blinking.
So if you start it blinking you need to stop the blinking
and then turn the light off. Here's the code:
program lightingUp
{
#include<spybot.h>
main{
LED[iVLLBlinkInterval] = 10
LED[iVLLBlink] = 1
wait 100
LED[iVLLBlink] = 0
LED[iVLL] = 0
}
}
So that's it! You can now turn all the Spybot's lights on
and off as often as you like. There is another method for
controlling the ARC lights which is more efficient than this
one. If you think your ready then move on to Lighting
Up (Part 2). |