NQC Tutorial

-Installing Bricx Command Center Integrated Development Enviroment(IDE)
    Download Bricx Command Center(BCC) from Source Forge and follow the installation instructions.


-Programming in NQC
    NQC is very similar to C, but it is Not Quite C (..thus NQC).  NQC does not have arrays, and has special libraries for use with the lego brick.

-Downloading the firmware
    In the BCC you can download the firmware by clicking on the download firmware menu option.
    From the command line you can download the firmware by typing
       nqc -firmware ./firm0328.lgo

-Compiling the Program
    In BCC you can just click on the button that says compile
    From the command line you can compile by typing
       nqc Program1.nqc
          //produces Program1.rcx

-Downloading the Program
    In BCC you just click the blue download button
    From the command line you can download by typing
       nqc -d Program1.rcx

-Programming in NQC
    NQC is similar to C.  Creating a main method is as follows
   
          task main()
             {
                statement1;      //statements in NQC
                statement2;
             }

-NQC has the type int, boolean condtions and the binary operators.
-NQC has the tasks, void and sub types of methods.
       -tasks are methods that can run in the background.
       -void methods have no return type
       -sub are just methods with no return type
-NQC also has special methods used to read sensors and run motors.  


Motors
Motor Variables
    -There are three motor variables that are used to refer the the three outputs on the Lego brick.
OUT_A
OUT_B
OUT_C

-Motors Methods
On("motor/motors"); Turns on these motors
Off("motor/motors"); Turns off these motors(hard)
Float("motor/motors"); Turns off these motors(soft)
Fwd("motor/motors"); Turn these motors on forward
Rev("motor/motors"); Turn thesee motors on reverse
Toggle("motor/motors"); Swap forware and reverse
OnFwd("motor/motors"); Turn the motors on forward
OnRev("motor/motors"); Turn the motors on reverse

Ex.
    On(OUT_A);
    Off(OUT_B + OUT_A);


SetPower("motor/s", Power); Power value 0-9 for the specified motors
SetDirection("motor/s","Direction");
Set the direction of the motors specified
OUT_FWD
OUT_REV
OUT_TOGGLE
SetOutput("motor/s","Type")
Sets these motors to this type of output
OUT_ON
OUT_OFF
OUT_FLOAT
OnFor("motor/s", time )
Turns the motors on for the specified amount of time
(Time in milliseconds)
1000 = 1 second

Ex.
    SetPower(OUT_A, 6);
    SetDircetion(OUT_A + OUT_B, OUT_FWD);
    OnFor(OUT_C, 100);



Sensors

-Sensor Variables
    -There are three sensor variables that are used to refer the the three inputs on the Lego brick.
SENSOR_1
SENSOR_2
SENSOR_3


-Sensor Methods
SetSensor("sensor",type); Sets the sensor "sensor" to the specified type
  SENSOR_TOUCH (0 or 1)
  SENSOR_LIGHT (integer valued)
int x = SENSOR_1;
Sets x to the value of SENSOR_1
SetSensorType("sensor", type); Sets the sensor "sensor" to the specified type
  SENSOR_TYPE_TOUCH
  SENSOR_TYPE_LIGHT
  SENSOR_TYPE_TEMPERATURE
  SENSOR_TYPE_ROTATION 
SetSensorMode("sensor", type); Sets the sensor "sensor" to the specified mode
  SENSOR_MODE_RAW  (0-1023)
  SENSOR_MODE_EDGE (# of all transitions)
  SENSOR_MODE_PULSE (# of High transitions)
  SENSOR_MODE_PERCENT (0-100)
  SENSOR_MODE_ROTATION (0-16)
  SENSOR_MODE_CELSIUS
  SENSOR_MODE_FAHRENHEIT
  SENSOR_MODE_BOOL (0-1)
ClearSensor("sensor"); Clears the particular sensor(Edge counters).



LCD Display

-LCD Commands
SelectDisplay(mode)
Sets the display to the specified variable
DISPLAY_WATCH
DISPLAY_SENSOR_1
DISPLAY_SENSOR_2
DISPLAY_SENSOR_3
DISPLAY_OUT_A
DISPLAY_OUT_B
DISPLAY_OUT_C
SetUserDisplay (var,places); sets the LCD to show the variable "var" to the specified number of places "places".


-Other Commands
Wait(int time)
PlaySound(int Number)
PlayTone(const freq, int time)