RobotC Frequently Used Commands (RCX)

Motors
Timers
Sensors
Sound/Display
Miscellaneous
motor
wait1Msec
SetSensorType
PlayTone
random
bMotorFlippedMode
wait10Msec
SensorValue
PlaySound
bFloatDuringInactiveMotorPWM
time1
ClearSensorValue
SetUserDisplay
time10
time100
ClearTimer

Motors
Basic motor control commands, plus some fine-tuning commands.

motor[output] = power;
RCX

Turn the referenced RCX motor output either on or off and also sets the power level of the motor outputs.

The RCX has 3 motor outputs: motorA, motorB, motorC

The RCX can handle power levels from -100 (full reverse) to 100 (full forward). A power level of 0 will cause the motors to stop.

	motor[motorA] = 100;  //Output A - full speed forward
	motor[motorB] = 100;  //Output B - full speed forward

bMotorFlippedMode[output] = 1 or 0;
RCX

This feature is used to reverse the direction the referenced motor travels. Once this setting is changed, the reference motor will be reversed for the entire program (unless manually changed a later point in the program)

This is useful for when working with motors that mounted in different directions and the programmer wants to keep the power setting the same for both motors.

There are two settings: 0 - normal, 1 - reversed

Before:

	motor[motorA] = -100;  //Output A - full speed reverse
	motor[motorB] = 100;   //Output B - full speed forward

After:

	bMotorFlippedMode[motorA] = 1; //Motor Direction Flipped
	motor[motorA] = 100;           //Output A - full speed reverse
	motor[motorB] = 100;           //Output B - full speed forward

bFloatDuringInactiveMotorPWM = true or false;
RCX

This switch is used to choose wether the motors on the RCX will float or break when there is no power applied. By default, the motors will float.

The reason to switch this is if you're trying to make precise turns with the RCX and the motors are drifting causing the change in direction to be off.

There are two settings for this switch:
false - motors will brake when inactive
true - motors will float when inactive

	bFloatDuringInactiveMotorPWM = false; //motors will brake when power is set to "0"

Timers
The RCX allows you to use Wait commands to place delays in your program. It also supports Timers, which work like stopwatches - they count time since the last reset, and you reset them again when you want to start or restart.

wait1Msec(wait_time);
RCX

This function will cause a program to wait a specified number of milliseconds before executing the next instruction in a program.

Wait_time is an integer (1 = 1/1000th of a second). Maximum wait time is 32.768 seconds when using this function.

	motor[motorA] = 100;  //Output A - full speed forward
	wait1Msec(2000);      //Wait 2 seconds
	motor[motorA] = 0;    //Output A - off

wait10Msec(wait_time);
RCX

This function will cause a program to wait a specified number of hundredths of a second before executing the next instruction in a program.

Wait_time is an integer (1 = 1/100th of a second). Maximum wait time is 327.68 seconds when using this function.

	motor[motorA] = 100;  //Output A - full speed forward
	wait10Msec(200);      //Wait 2 seconds
	motor[motorA] = 0;    //Output A - off

time1[timer] = time;
RCX

This timer function returns the current value of the referenced timer as an integer in a specific resolution. The resolution for "time10" is in milliseconds (1 = 1/1000th of a second).

The maximum amount of time to be recorded is 32.768 seconds (~1/2 minute)

The RCX has 4 internal timers: T1, T2, T3, T4

	int x;  //Init variable x
	x = time1[T1];  //assign variable x value of Timer #1 (1/1000th seconds)

time10[timer] = time;
RCX

This timer function returns the current value of the referenced timer as an integer in a specific resolution. The resolution for "time10" is in hundredths of a second (1 = 1/100th of a second).

The maximum amount of time to be recorded is 327.68 seconds (~5 minutes)

The RCX has 4 internal timers: T1, T2, T3, T4

	int x;  //Init variable x
	x = time10[T1];  //assign variable x value of Timer #1 (1/100th seconds)

time100[timer] = time;
RCX

This timer function returns the current value of the referenced timer as an integer in a specific resolution. The resolution for "time100" is in tenths of a second (1 = 1/10th of a second).

The maximum amount of time to be recorded is 3276.8 seconds (~54 minutes)

The RCX has 4 internal timers: T1, T2, T3, T4

	int x;  //Init variable x
	x = time100[T1];  //assign variable x value of Timer #1 (1/10th seconds)

ClearTimer(timer);
RCX

Resets the referenced timer back to zero seconds.

The RCX has 4 internal timers: T1, T2, T3, T4

	ClearTimer(T1);  //Clear Timer #1

Sensors
Sensor commands for configuration and usage are listed below. Most sensor setup should be done through the Robot > Motors and Sensors Setup menu for best results.

SetSensorType(sensor_input,sensor_type);
RCX

This function is used to manually set the mode of a specific input port to a specific type of sensor. We recommend, however, that you use the "Motor and Sensors Setup" wizard in RobotC.

The RCX has 3 sensor inputs: S1, S2, S3

The RCX supports 6 different types of sensors:

Sensor Type
Description
Range of Values
sensorRawValue Analog, Raw Values 0 to 1023
sensorTouch Digital 0 to 1
sensorTemperature Analog, Celcius 0.0 to 100.0
sensorReflection Analog, Percentage 0 to 100
sensorRotation Digital with Directional Counter -32768 to 32768
sensorActiveRawValue

Analog, Raw Values
(With Voltage)

0 to 1023
   SetSensorType(S1, sensorTouch);  //Input 1 now is set to be a Touch Sensor

SensorValue(sensor_input)
RCX

SensorValue is used to read the value of the referenced sensor port. Values will correspond to the type of sensor set for that port (see set_sensor_type page).

The SensorValue function can be accessed like a variable, as it returns an integer value.

The RCX has 3 sensor inputs: S1, S2, S3

	SetSensorType(S1, sensorTouch);  //Input 1 now is set to be a Touch Sensor
	
	if(SensorValue(S1) == 1)
	{
		motor[motorA] = 100;  //Output A - full speed forward
	}

ClearSensorValue(sensor_input)
RCX

This function is used to reset the value of the referenced sensor port back to zero. This is only neccessary with specific sensor types that retain their values (e.g. Encoder Sensor).

The RCX has 3 sensor inputs: S1, S2, S3

	SetSensorType(S1, sensorRotation);  //Input #1 now is set to be a Rotation Sensor
	ClearSensorValue(S1); //Reset Input #1 back to a value of 0

Sounds
The RCX can generate tones, or play back stored waveform sound data.

PlayTone(frequency, duration)
RCX

Plays a sound from the RCX internal speaker at a specific frequency (1 = 1 hertz) for a specific length (1 = 1/100th of a second).

	PlayTone(220, 500);  //Plays a 220hz tone for 1/2 second

PlaySound(sound_name);
RCX

Plays a sound effect from the RCX internal library. Requires a sound name to be passed to play the sound.

Sound Names
soundBlip
soundBeepBeep
soundDownwardTones
soundUpwardTones
soundLowBuzz
soundFastUpwardTones
soundShortBlip
soundException
	PlaySound(soundUpwardTones);  //Plays the sound "Upward Tones"

LCD Display
Commands for the RCX's LCD Display.

SetUserDisplay(int);
RCX

This function allows the user to display a value on the LCD screen of the RCX.

The RCX screen is only able to display up to 4 characters at one time.

	int x;  //declares x as an integer
	x = 200;  //Assigns the variable "x" with the value of 200
	SetUserDisplay(x); //The value of x (200) will be displayed on the LCD

Miscellaneous
Miscellaneous useful commands that are not part of the standard C language.

random(value);
RCX

Returns a random number (integer) between 0 and the 'value' of the function.

	int x;  //declares x as an integer 
	x = random(100); //Returns a random value between 0 and 100