Concept Explanation: #pragma

Printer-friendly version

 

Before you use a motor, you must configure the NXT to access it. This brings us to our next rule:

RobotC Rule 4: A #pragma command is required for each connected device you wish to use.

To make writing programs easier, RobotC provides a tool to generate the configuration commands. To access this tool, go to the following menu location:

Robot > Motors and Sensors Setup

The only thing we need to do in that screen is label our motors. This tool will not generate #pragma commands for unlabeled devices. We don't need to modify any other settings. On our robot, the left motor is in Port A which is motorA in this tool. The Right motor is in Port C which is motorC. Here a screenshot of what the Motor tab looks like for the sample program.

MotorSetup

Once you Press "OK" in this menu, you should get the following instructions at the top of your program:

MotorSetup-Result

These instructions let the NXT know that there are peripherals attached. If you make changes to your NXT, you can come back to the Motor and Sensor Setup tool to update the configuration.