1 / 8

NQC Program Structure

NQC Program Structure. 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions. Syntax task name ( ) { //task body } Example. Program must have task named “main” Program may have up to 10 tasks

Télécharger la présentation

NQC Program Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NQC Program Structure • 3 types of code blocks with their own features and limitations • 1. Tasks • 2. Subroutines • 3. Inline Functions

  2. Syntax task name ( ) { //task body } Example Program must have task named “main” Program may have up to 10 tasks Implement tasks using “start” & “stop” (except “main” task) Tasks

  3. Syntax sub name ( ) { //subroutine body } Single copy of code is shared by different callers (efficient) Cannot use arguments Cannot call other subs 8 subs maximum No local variables- called from multiple tasks Mostly used when code size is limited Subroutines

  4. Syntax void name (arguments) { //Function body } Leads to excessive code size (each call adds copy) “return” causes function to return Arguments Empty, one, more Correct number & type Defined by “type” followed by “name” example Inline Functions

  5. Argument types

  6. 16 bit signed integers Max 32 variables Declared & initialized same as in Java Global variables declared outside block Local variables accessible inside block where defined Example: int x; // global task main ( ) { int y; // local to main {// compound stment int z; // local to cmpd y = z; // valid asgmnt } y = z; // error- z not in scope Variables

  7. SENSOR_1, 2, or 3 identifies RCX sensor ports You can set the type and the mode for each sensor For convenience just use SetSensor Examples: SetSensorType (SENSOR_1, SENSOR_TYPE_LIGHT); SetSensorMode(SENSOR_1, SENSOR_MODE_PERCENT); SetSensor(SENSOR_1, SENSOR_LIGHT); Sensors

  8. Out_A, B, or C identifies output ports 3 attributes: Mode On, Off , Float Direction Fwd,Rev, Toggle Power level SetPower(Out_A,7) Examples: OnFwd(Out_A); Rev (Out_B); Off(Out_A+Out_B); OnFor(Out_C,100); MISC Wait(time); time = 100ths sec Outputs

More Related