4nqc_found1

Document Sample
4nqc_found1 Powered By Docstoc
					            NQC: Not Quite C
                (last updated 9/14/05 2:24pm)

• Each NQC program has a task main ()
• The program is contained within curly braces
  { ….. }

  task main()
  {
      SetSensor(SENSOR_1, SENSOR_TOUCH);
      OnFwd(OUT_A);
      until(SENSOR_1 == 1);
      Off(OUT_A);
  }
  task main()
  {
      SetSensor(SENSOR_1, SENSOR_TOUCH);
      OnFwd(OUT_A);
      until(SENSOR_1 == 1);
      Off(OUT_A);
  }
Statements are separated by ;
The language is case sensitive
  OnFwd(OUT_A) is different from onfwd(OUT_A)
   task main()
   {
       SetSensor(SENSOR_1, SENSOR_TOUCH);
       OnFwd(OUT_A);
       until(SENSOR_1 == 1);
       Off(OUT_A);
   }
SENSOR_1 refers to the sensor on sensor port 1
SetSensor defines SENSOR_1 to be a touch sensor
OUT_A refers to the output port A
OnFwd(OUT_A) turns on port A in forward direction
OnFwd(OUT_A+OUT_B) turns on port A & port B in
  forward direction
        The until statement
until(condition) body ;
    Executes the body zero or more times until
    the condition is true.
Assignment operator: x=5 assigns the
 value 5 to the variable x.
Relational operator: x==5 has a value
    true if the value of x is 5
    false if the value of x is not 5
  until(SENSOR_1 == 1) ;
      sensor 1 is a touch sensor
      The output of a touch sensor is binary
         when the switch is open the output is 0
         when the switch is closed the output is 1
  When the sensor is open, what statement is
  executed?
       The null statement
       You don’t have to leave any spaces
       The ; indicates the end of this statement.

When the sensor is open, the null statement
is executed over and over again. It is like
the program holds on this statement until
the switch is closed.
Several forms of the until statement

  until(SENSOR_1 == 1) ;
  ---------------------------------------------------------
  until(SENSOR_1 == 1) OnFwd(OUT_B);
  ---------------------------------------------------------
  until(SENSOR_1 == 1)                    note: no ; here
  {
        On(OUT_A);
        On(OUT_B);

  }          note: no ; here
                Comments
  task main()
  {
      SetSensor(SENSOR_1, SENSOR_TOUCH);
      // Execution of the following statement turns
      // on output port A to full value.
      OnFwd(OUT_A);
      until(SENSOR_1 == 1);
      Off(OUT_A);
  }
All characters following // until the end of
a line are treated as comment.
  What do the following statements do?


Float(Out_B);
Rev(Out_B);
Toggle(Out_A + Out_B);
OnFwd(Out_A); // turn on A in forward direction
OnRev(Out_A);
On(Out_A);    Turns A on. If the last state was reverse,   it will
                      now be in reverse.
           Controlling Timing


OnFor(OUT_A, 100);
  Turns A on for 1 second
Note
  OnFor(outputs, duration);
Is different from
  OnFwd(outputs);
        Controlling Power Output


SetPower(OUT_A+OUT_B, 0);
  Sets the power to A & B to it’s lowest value
SetPower(OUT_A+OUT_B, 7);
  Sets the power of A & B to it’s highest value
SetPower(OUT_A+OUT_B, OUT_FULL);
  Same as the preceeding statement
How many output levels are there?
                 Using #define
You can name various motors and
sensors

#define LEFT_TREAD OUT_A                     note below

On(LEFT_TREAD);

Allows you to remember what is attached
to different ports.
Note: Statements which begin with # are directives for
the preprocessor they do not have semicolons following
them.

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:1
posted:3/20/2013
language:English
pages:11