FSHS Robotics

Back to Outline

FSHS Robotics C Course

NXT: Displaying Reflected Light Values

  1. Set up a sensor by going to Robot > Motors and Sensors Setup. Make sure you name it what you’ll put in the square brackets!

  2. To get sensor values:

int leftVal = SensorValue[sensorLeft];
int rightVal = SensorValue[sensorRight];

To display sensor values, you can display it in the 'Debug Stream', a window on your computer that you can dump values into. You can open this window through Robot > Debugger Windows > Debug Stream. If you can't see this option, set yourself to superuser! That can be done in Window > Menu Level > Super User.

writeDebugStreamLine("%d %d", leftVal, rightVal);

  1. Put it into a loop to always update those numbers on the NXT 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];
                writeDebugStreamLine("%d %d", leftVal, rightVal);
        }
}

Run the program and see if it displays the numbers.

© Fort Street High School Robotics