Sample RobotC Programs

RobotC is installed with a large set of sample programs that illustrate various programming concepts and techniques. A summary of these files includes the following:

File Name



This program is used to measure the real-timer performance of the RobotC interpreter on the NXT. It measures the time to execute 10 different “opcodes’ on the NXT. The time to repetitively loop executing a single opcode is measured and the overhead of an empty loops is subtracted. The resultant time is normalized to get the number of microseconds to execute each of the ten opcodes. Results range from 2 to 50 microseconds.  


Program uses both “brake” and “float” mode to illustrate how ‘brake’ mode provides a more linear relationship between power level and actual speed. Two graphs are drawn on the NXT LCD screen for comparison purposes.

Motor Distance vs Time.c

Program graphs the distance traveled vs speed to show the linear relationship. The graph is drawn on the NXT LCD screen.

Motor Float Mode Test.c

Program demonstrates the difference between ‘float’ and ‘brake’ mode for holding a motor in position.

Motor Speed PID.c

Program demonstrates the use of built-in PID (Program, Integral and Derivative) algorithms for precise control over motor speed.

NXT Battery Level.c

Program shows how to read the current and average battery levels and display on the NXT LCD screen.

NXT Bluetooth Test.c

Program demonstrates how to access some Bluetooth functions from a user application program.

NXT Compass Sensor.c

This program demonstrates the use of 3rd party compass for the NXT. The compass heading is continuously obtained and displayed on the NXT LCD screen.

NXT Compass Sensor Driver.c

This program contains a device driver for the Hitechnic Compass Sensor. With only a few small changes it can also be used for the Mindsensors compass.

NXT Button.c

This program illustrates how to use the LEFT, RIGHT, ENTER and EXIT buttons within a user program.

NXT Button Advanced.c

This is a more advanced program for using the NXT front panel buttons within a program. It illustrates the use of a user created menu for item selection using the NXT buttons

NXT Draw Spiral.c

This program just loops forever drawing a spiral and then erasing it on the NXT LCD screen. It illustrates use of the set and clear pixel functions for the NXT display and also the ‘sin’ and ‘cos’ trigonometric functions.

NXT Test File IO.c

This program illustrates opening and closing, and reading and writing files on the NXT from within a user program. It also illustrates use of the “file delete” function.

NXT File Searching.c

This program illustrates using wildcards (“*”) to perform a search through NXT files.

NXT Mindsensors Motor MUX.c

This prora millustrates use of the MindSensors motor multiplexor.

NXT Motor Synchronization.c

Program demonstrates synchronization of two motors on the NXT. The “slave” motor is set to turn at 50% of the speed of the main/primary motor.

NXT Position Control.c

Program demonstrates precise motor movement on the NXT. The motor is set to loop where it continuously moves 6 encoder counts. There is no overshoot in the motor movement.

NXT Songs.c

This file illustrates use of the NXT sound handling capabilities to play three different songs on the NXT speaker. It illustrates the ability to queue sounds (RobotC supports up to 10 queued sound items) and how to test whether there is space available in the sound queue.

NXT Test Datalog.c

Program illustrates the use of data logging with the NXT.

NXT Test Task.c

Program illustrates multiple tasks on the NXT.

NXT Trig Demo.c

This program illustrates use of the NXT motor encoder as a sensor input, floating point variables, NXT LCD display functions and trig functions. It uses the input from a motor encoder as an angle and then graphical draws this angle on the NXT LCD. The numeric sine and cosine values are also displayed on the screen.


Program illustrates the use of various NXT LCD drawing functions. It also times the execution time for the various functions.

State Machine Template.c

State machines are one convenient method for architecting the control of a robot. This program provides a generic template for writing a state machine.

NXT-G Move Block Basic.c

This program contains a function that emulates the capabilities of the MOVE block in the NXT-G graphical programming language.

Random Test.c

This program illustrates use of the “random()” function.


This is the source code for the “on brick programming” playback program on the NXT.

Stalled Motor Check.c