Knowledge Base‎ > ‎Robotics‎ > ‎Robotics Summative‎ > ‎

NXC Cheat Sheet

Structure

{} - used to denote a block of code
; - used at the end of each line
// - single line comment
/*   */  - multi - line comment


Operators

+     addition
-     subtraction
*   multiplication
/     division

==    equal to
<     smaller than
<=    smaller than or equal to
>      larger than
>=     larger than or equal to
!=     not equal to

&&    boolean and
!=      boolean or

Motors
Outputs - can be OUT_A, OUT_AC, etc.

Off(Output) - turn motor off
OnFwd(Output, Speed %) - set motor ahead at speed


Timing 

Wait(msec) - wait for given time
Constants

#define MOVE_TIME  1000
- create a constant called MOVE_TIME set to 1000


Control

repeat(4) {       }
- repeat block of code # of times

while(condition) {       }
- repeat block of until condition is false

if(condition) { 
    // do something if condition true
else {
    // do something if false
}




Variables

int speed; - define a variable of type integer
speed = 100; - assign a value of 100 to speed
short, long, byte, bool and string

Comments