110 likes | 201 Views
NQC: Main Program. task main() { OnFwd(OUT_A); OnFwd(OUT_B); Wait(400); OnRev(OUT_A+OUT_B); Wait(400); Off(OUT_A+OUT_B); }. Statement Block. NQC: Main Program. void turn_around() { OnRev(OUT_C); Wait(340); OnFwd(OUT_A+OUT_C); } task main() { ……………………… ..
E N D
NQC: Main Program task main() { OnFwd(OUT_A); OnFwd(OUT_B); Wait(400); OnRev(OUT_A+OUT_B); Wait(400); Off(OUT_A+OUT_B); } Statement Block
NQC: Main Program void turn_around() { OnRev(OUT_C); Wait(340); OnFwd(OUT_A+OUT_C); } task main() { ……………………….. turn_around(); Wait(200); turn_around(); ……………………….. Off(OUT_A+OUT_C); } Function Block Statement Block
NQC: Main Program int move_time, turn_time; task main() { while(true) { move_time = Random(60); ………………………………. OnRev(OUT_A); Wait(turn_time); } } Defining global variables Statement Block
NQC: Main Program task main() { SetSensor(SENSOR_1,SENSOR_TOUCH); start check_sensors; start move_square; } task move_square() { …………………………………. } task check_sensors() { …………………………………… } Multi-tasking Task 1 Task 2
NQC: Setting up Sensors Variable corresponding to Channel 1 • SetSensor(SENSOR_1, SENSOR_TOUCH); • SetSensor(SENSOR_2, SENSOR_LIGHT); • SetSensor(SENSOR_3,SENSOR_ROTATION); • SetSensor(SENSOR_1, SENSOR_CELSIUS); • SetSensor(SENSOR_2, SENSOR_FAHRENHEIT); • SetSensor(SENSOR_3, SENSOR_PULSE); Touch Sensor
NQC: Outputs • SetOutput(outputs, mode) • Set the outputs to the specified mode. Outputs is one or more of OUT_A, OUT_B, and OUT_C. Mode must be OUT_ON, OUT_OFF, or OUT_FLOAT. SetOutput(OUT_A + OUT_B, OUT_ON); // turn A and B on
NQC: Outputs • Output Mode • OUT_OFF //output is off (motor is prevented from turning) • OUT_ON //output is on (motor will be powered) • OUT_FLOAT //motor can "coast"
NQC: Outputs • SetDirection(outputs, direction) • Set the outputs to the specified direction. Outputs is one or more of OUT_A, OUT_B, and OUT_C. Direction must be OUT_FWD, OUT_REV, or OUT_TOGGLE. SetDirection(OUT_A, OUT_REV);
NQC: Outputs • Direction • OUT_FWD Set to forward direction • OUT_REV Set to reverse direction • OUT_TOGGLE //Switch direction to the opposite of what it is presently
NQC: Outputs SetPower(outputs, power) • Sets the power level of the specified outputs. Power may be an expression, but should result in a value between 0 and 7. The constants • OUT_LOW, • OUT_HALF, and • OUT_FULL may also be used. • SetPower(OUT_A, OUT_FULL); // A full power • SetPower(OUT_B, x);
NQC: Outputs On(outputs) On(OUT_A + OUT_C); Off(outputs) Off(OUT_A); Fwd(outputs) Fwd(OUT_A); Rev(outputs) Rev(OUT_A); Toggle(outputs) Toggle(OUT_A); OnFwd(outputs) OnFwd(OUT_A); OnRev(outputs) OnRev(OUT_A); OnFor(outputs, time) OnFor(OUT_A, x);