09NQCSyntax

# 09NQCSyntax - { Square(distance); distance = distance + 50;...

This preview shows pages 1–5. Sign up to view the full content.

NQC Syntax Comp106 4 Basic Programming Constructs • Sequence • Decision • Repetition • Sub-program

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Convert Programs task main() { Forward(100); repeat (3) { SpinRight(100); Backward(50); } Off(OUT_A+OUT_C); } Another Conversion task main() { int counter = 0; while (true) { if (counter == 0) { Forward(100); counter = counter + 1; } else { Backward(100); counter = counter - 1; } } } We can also use the “until” loop Declare variables before use
Increasing Square #define RIGHT_ANGLE 100 void Square(int length) { repeat (4) { Forward(length); Spin_right(RIGHT_ANGLE); } } task main () { int distance = 0; while (true)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { Square(distance); distance = distance + 50; } } Constants Sensors • Must use SetSensor command first before we can use them. • Go forward until sensor 1 is touched: Beware of Loops • In NQC, loop conditions are NOT interrupt based (unlike the RCX GUI). • Cannot write programs the same way! • Event handling will be covered in tutorial #7. Using Timers • Use the SetTimer function to reset a timer. • Hit a wall and come back the same distance. • Note the use of the FastTimer function to read timer value. Tutorial #6...
View Full Document

## This note was uploaded on 09/16/2010 for the course COMP 106 taught by Professor Jasonmadar during the Fall '07 term at Capilano.

### Page1 / 5

09NQCSyntax - { Square(distance); distance = distance + 50;...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online