Download presentation
Presentation is loading. Please wait.
Published byJan-Erik Dahlen Modified over 5 years ago
1
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions
2
Tasks 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)
3
Subroutines Cannot use arguments 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
4
Inline Functions 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
5
Argument types TYPE MEANING LIMITATION int Pass by value none
const int Constants only int& Pass by reference Variables only const int& Cannot modify argument
6
Variables 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
7
Sensors 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);
8
Outputs 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.