09NQCSyntax

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

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

View Full Document Right Arrow Icon
NQC Syntax Comp106 4 Basic Programming Constructs • Sequence • Decision • Repetition • Sub-program
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
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 Right Arrow Icon
Ask a homework question - tutors are online