Spybots Smart Parts  
  The Unofficial Resource Centre for Lego Spybotic  
   
img  
   
   

TUTORIALS

TUTORIALS

BASIC

my first program - nqc

Tutorial Details:
Difficulty Level: Basic
Topics Covered: Basic programming structure for NQC.
Assumed Knowledge: THe Basics
Written By: BILL LANE

Print Version

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.

 

This tutorial is protected by International Intellectual Property Rights laws and may not be reproduced or redistributed in full or part, without the prior written consent of the author. Unauthorized reproduction of this tutorial or its contents may result in prosecution.

 

 
 
DISCLAIMER: All content is provided as is, with no warranty stated or implied regarding the quality or accuracy of any content on or off this site. All trademarks, service marks, and copyrights are property of their respective owners. This site is not sponsored, authorized or sanctioned by the LEGO Group nor representative of their opinions in any way.PRIVACY POLICY