FSHS Robotics

Back to Outline

FSHS Robotics C Course

NXT: Printing to the screen

Printing to the screen is much like printf and printing to the debug stream.

This code prints “Hello world!” on the first line of the NXT brick screen:

nxtDisplayTextLine(1, "Hello world!");

To print numbers, you can do this:

nxtDisplayTextLine(1, "Value: %d", sensorLeft);

If there is something already on line 1 when you are printing, it will overwrite the contents of that line.

View light values on the screen

Recall our previous program that showed left and right sensor values onto the Debug stream. We can really easily change that to display it onto the screen:

#pragma config(Sensor, S1, sensorLeft, sensorLightActive)
#pragma config(Sensor, S2, sensorRight, sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() {
        while(1) {
                int leftVal = SensorValue[sensorLeft];
                int rightVal = SensorValue[sensorRight];
                nxtDisplayTextLine(3, "%d", leftVal);
                nxtDisplayTextLine(4, "%d", rightVal);
        }
}

Run the program and see if it displays the numbers.

© Fort Street High School Robotics