80 likes | 150 Views
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
E N D
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 Implement tasks using “start” & “stop” (except “main” task) Tasks
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
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
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
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
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