Tutorial Details:
Difficulty Level:
Basic
Topics Covered: Basic
programming structure for NQC.
Assumed Knowledge:
THe Basics
Written By: BILL LANE
BACK
Creating a basic NQC program is very simple. Below is an
example of a simple program that will run one motor indefinitely:
task main()
{
On(OUT_A);
}
Let's take this one step at a time. The first word is task.
In everyday life a task is a job that needs doing. So what
we're doing here is defining a job that we want to the controller
to perform.
The next element is main().
This is the name of the task. We can use a tasks name to tell
it to run when it's needed. But main()
is a special name. All NQC scripts must have a main task.
This is the first task the brick will try to perform. It is
from this task that we can call any other tasks we may want
to perform.
The next element is {
(opening curly bracket). This indicates the start
of the statements that the task will need to perform. The
end of the statements is defined by a }
(closing curly brace).
Between the two curly brackets go all the instructions we
want the brick to perform. In our example we have just one
instruction. But the number of instructions is only really
limited by the size of the brick's memory.
The final element to note is the ;
(semi colon). This indicates the end of the current
instruction.
So that's it! You've created your first NQC program. If you
haven't done so already try downloading it and taking your
robot for a spin.
|