top of page
Why hello there! Find out the TheBasics of Bricx Command Center Here!
Your robot will only "read" the code (commands) if it is within the task called "main". The task is declared by writing "task main () {...code here... }", as shown in the picture.
 
The code (commands) must be written within the two curly brackets so that the NXT Robot can read the commands.
Basic Robot Commands (Forward, Reverse, etc.)
The simplest thing you can do with your robot is to get it to move forward and back. Remember that every command must end in a semicolon (;)
 
You will need to turn on the motor(s) and set it's direction of movement, as well as it's speed (0-100).
 
OnFwd (OUT_AB, 100); - Tells robot to power the motors connected to output A and B in a forward direction. A reverse direction can be acheived by using OnRev (OUT_AB, 100); 
 
Wait(5000); - You must put a "Wait (time)" so the robot knows how long to power the motors for. 5000 is equivalent to 5 seconds. The robot does not read the next command till the 5 seconds is complete.
You can also turn your robot by setting only one of the motors to spin. By only powering one of the wheels, the robot will rotate. Like this:
 
 
You can also turn off a motor of choice by using the Off(OUT_AB); command.
 
The Off(OUT_motorOUTPUT) command combined with the Wait(time) command can be used to stop the robot from moving for a particular time. 
 
Sample Code (left); Robot moves forward moves for 5 seconds, and then comes to a stop. The robot stays motionless for 5 seconds and the moves forward again for 5 seconds.

Motor OUTPUT (ABC), Motor Speed

Time (ms)

Rotates Robot

To make your code more efficient and organized, you can define a constant variable that will store a constant number. 
 
Format: #define constantName Value;
Example: #define WaitTime 5000;
 
Sample code to the right utilizes this.
Declaring Variables and Setting Sensors for Use (Light,Touch, etc)
Before using any of the sensors on your NXT robot you must set them.
 
Setting them will prepare them to send inputs to the NXT robot.
 
Format: SetSensorTYPE (IN_#(1-3));
Example: SetSensorLight (IN_1); 
 
 
To keep track of numbers and values through out your program variables can be used. Variables allow the coder to store values. These variables can be accesed universally through out the program.
 
Types: int, short, long, byte, bool and string.
 
 

Copyright 2012 NXT REFERENCE. No Robots were harmed in the making. 

bottom of page