ROBOTC for Beginners - NXT:
Wait Functions:
Title Picture Description Default Usage and Sample Usage and Sample with Parameters

Wait Wait an amount of time measured in seconds.

wait(time)
default time: 1.0 seconds

forward();
wait();
stop();


wait(time)
To go forward for 2.7 seconds:

forward(50);
wait(2.7);
stop();



Wait in Milliseconds Wait an amount of time measured in milliseconds.

waitInMilliseconds(time)
default time: 1000 milliseconds

forward();
waitInMilliseconds();
stop();


waitInMilliseconds(time)
To go forward for 2700 milliseconds:

forward(50);
waitInMilliseconds(2700);
stop();



Movement Functions:
Title Picture Description Default Usage and Sample Usage and Sample with Parameters

Forward Both wheels rotate forward at the same speed and the robot moves straight forward.

Range: -100 to 100
(Forward will always move your robot forward.)

forward(speed)
default speed: 75

forward();
wait();
stop();


forward(speed)
To go forward at speed 50 for 2.0 seconds:

forward(50);
wait(2.0);
stop();



Backward Both wheels rotate backward at the same speed and the robot moves straight backward.

Range: -100 to 100
(Backward will always move your robot backward.)

backward(speed)
default speed: -75

backward();
wait();
stop();


backward(speed)
To go backward at speed 50 for 2.0 seconds:

backward(50);
wait(2.0);
stop();



Point Turn Both wheels rotate at the same speed but in opposite directions, causing the robot to turn around it's center. This makes a sharp turn in place.

Range: -100 to 100

pointTurn(direction, speed)
default direction: right
default speed: 75

pointTurn();
wait();
stop();

pointTurn(direction, speed)
To point turn left at speed 50 for 0.4 seconds:

pointTurn(left, 50);
wait(0.4);
stop();


Swing Turn One wheel rotates while the other does not move, causing the robot to turn around the stopped wheel. This makes a wide turn.

Range: -100 to 100

swingTurn(direction, speed)
default direction: right
default speed: 75

swingTurn();
wait();
stop();

swingTurn(direction, speed)
To swing turn left at speed 50 for 0.4 seconds:

swingTurn(left, 50);
wait(0.75);
stop();


Stop Both wheels do not move, causing the robot to stop.

stop()

forward();
wait();
stop();


stop()

forward(50);
wait(2.0);
stop();



Set Motor Set a motor to a speed.

Range: -100 to 100

Acceptable Motors: motorA, motorB, motorC
(and your names for them given in Motors and Sensors Setup.)

setMotor(motor, speed)
default motor: motorA
default speed: 75

setMotor();
wait();
stopMotor();


setMotor(motor, speed)
To set motorA to speed -25 for 0.5 seconds:

setMotor(motorA, -25);
wait(0.5);
stopMotor(motorA);



Stop Motor
Stops a motor.

Acceptable Motors: motorA, motorB, motorC
(and your names for them given in Motors and Sensors Setup.)

stopMotor(motor)
default motor: motorA

setMotor();
wait();
stopMotor();


stopMotor(motor)

setMotor(motorA, -25);
wait(0.5);
stopMotor(motorA);



Until Functions:
Title Picture Description Default Usage and Sample Usage and Sample with Parameters

Until Touch The robot does what it was doing until the touch sensor is pressed in.

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilTouch(sensor)
default sensor: S1

forward();
untilTouch();
stop();


untilTouch(sensor)
To go forward at speed 50 until touch sensor in port S3 is pressed:

forward(50);
untilTouch(S3);
stop();



Until Release The robot does what it was doing until the touch sensor is released.

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilRelease(sensor)
default sensor: S1

forward();
untilRelease();
stop();


untilRelease(sensor)
To go forward at speed 50 until touch sensor in port S3 is released:

forward(50);
untilRelease(S3);
stop();



Until Bump The robot does what it was doing until the touch sensor is pressed in and then released out.

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilBump(sensor)
default sensor: S1

forward();
untilBump();
stop();

untilBump(sensor)
To go forward at speed 50 until touch sensor in port S3 is pressed and then released:

forward(50);
untilBump(S3);
stop();


Until Sonar - Greater Than
The robot does what it was doing until the sonar sensor reads a value greater than a set distance in centimeters.

Range: 0 to 255

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilSonarGreaterThan(distance, sensor)
default distance: 30 centimeters
default sensor: S4

forward();
untilSonarGreaterThan();
stop();

untilSonarGreaterThan(distance, sensor)
To go forward at speed 50 until the sonar sensor reads a value greater than 45 centimeters in port S2:

forward(50);
untilSonarGreaterThan(45, S2);
stop();


Until Sonar - Less Than
The robot does what it was doing until the sonar sensor reads a value less than a set distance in centimeters.

Range: 0 to 255

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilSonarLessThan(distance, sensor)
default distance: 30 centimeters
default sensor: S4

forward();
untilSonarLessThan();
stop();

untilSonarLessThan(distance, sensor)
To go forward at speed 50 until the sonar sensor reads a value less than 45 centimeters in port S2:

forward(50);
untilSonarLessThan(45, S2);
stop();


Until Button Press
The robot does what it was doing until a button on the NXT is pressed.

Acceptable Buttons:
centerBtnNXT, rightBtnNXT, leftBtnNXT

untilButtonPress(nxtButton)
default button: centerBtnNXT

forward();
untilButtonPress();
stop();

untilButtonPress(nxtButton)
To go forward at speed 50 until the right triangle button is pressed on the NXT:

forward(50);
untilButtonPress(rightBtnNXT);
stop();


Until Light
The robot does what it was doing until the light sensor reads a value lighter than the threshold.

Range: (dark) 0 to 100 (light)

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilLight(threshold, sensor)
default threshold: 30
default sensor: S3

forward();
untilLight();
stop();

untilLight(threshold, sensor)
To go forward at speed 50 until the light sensor reads a value lighter than 45 in port S1:

forward(50);
untilLight(45, S1);
stop();


Until Dark
The robot does what it was doing until the light sensor reads a value darker than the threshold.

Range: (dark) 0 to 100 (light)

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilDark(threshold, sensor)
default threshold: 30
default sensor: S3

forward();
untilDark();
stop();

untilDark(threshold, sensor)
To go forward at speed 50 until the light sensor reads a value darker than 45 in port S1:

forward(50);
untilDark(45, S1);
stop();


Until Sound
The robot does what it was doing until the sound sensor reads a sound greater than the threshold.

Range: (silent) 0 to 100 (noisy)

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

untilSound(threshold, sensor)
default threshold: 50
default sensor: S2

forward();
untilSound();
stop();

untilSound(threshold, sensor)
To go forward at speed 50 until the sound sensor reads a value louder than 90 in port S4:

forward(50);
untilSound(90, S4);
stop();


Until Rotations The robot does what it was doing until the wheel rotations match the desired value.

Range: 0 to >65000

Acceptable Motors: motorA, motorB, motorC
(and your names for them given in Motors and Sensors Setup.)

untilRotations(rotations, motor)
default rotations: 1.0 rotations
default motor: motorB

forward();
untilRotations();
stop();

untilRotations(rotations, motor)
To go forward at speed 50 for 2.75 rotations, keeping track of the rotations on motorA:

forward(50);
untilRotations(2.75, motorA);
stop();


Until Encoder Counts The robot does what it was doing until the encoder counts match the desired value.

Range: 0 to >65000

Acceptable Motors: motorA, motorB, motorC
(and your names for them given in Motors and Sensors Setup.)

untilEncoderCounts(counts, motor)
default counts: 360 encoder counts
default motor: motorB

forward();
untilEncoderCounts();
stop();

untilEncoderCounts(counts, motor)
To go forward at speed 50 for 900 encoder counts, keeping track of the encoder counts on motorA:

forward(50);
untilEncoderCounts(900, motorA);
stop();


Line Following Functions:
Title Picture Description Default Usage and Sample Usage and Sample with Parameters

Line Track - For Time The robot will track a black line on a white surface for a specified time in seconds.

Threshold Range: (dark) 0 to 100 (light)

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

lineTrackForTime(time, threshold, sensor)
default time: 5.0 seconds
default threshold: 45
default sensor: S1

lineTrackForTime();
stop();


lineTrackForTime(time, threshold, sensor)
To track a line for 7.5 seconds, using a threshold of 60, with the light sensor in port S4:

lineTrackForTime(7.5, 60, S4);
stop();



Line Track - For Rotations The robot will track a black line on a white surface for a specified distance in rotations.

Threshold Range: (dark) 0 to 100 (light)

Acceptable Sensors: S1, S2, S3, S4
(and your names for them given in Motors and Sensors Setup.)

lineTrackForRotations(rot, threshold, sensor)
default rotations: 3.0 rotations
default threshold: 45
default sensor: S1

lineTrackForRotations();
stop();


lineTrackForRotations(rot, threshold, sensor)
To track a line for 4.75 rotations, using a threshold of 38, with the light sensor in port S4:

lineTrackForRotations(4.75, 38, S4);
stop();



(print me in landscape mode)