Skip to Main Content
The Art of LEGO MINDSTORMS NXT-G Programming
book

The Art of LEGO MINDSTORMS NXT-G Programming

by Terry Griffin
August 2010
Intermediate to advanced content levelIntermediate to advanced
288 pages
13h 21m
English
No Starch Press
Content preview from The Art of LEGO MINDSTORMS NXT-G Programming

a programmable timer, version 3

The Timer2 program has one potential problem: Because the Loop block checks the condition at the end of the loop, the timer will always wait at least one second. But what if the program determines that the delay should be zero or a negative number? The Timer2 program will still wait one second, which may not be the behavior you want.

To avoid pausing for one second when the delay is zero (or less), we need to check the loop condition at the start of the loop instead of at the end, as shown in the Timer3 program in Figure 10-28. In this program, the Compare block has been moved to the beginning of the loop, and the result is used to both exit the loop and control a Switch block. The Switch block makes sure that the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Art of LEGO MINDSTORMS EV3 Programming (Full Color)

The Art of LEGO MINDSTORMS EV3 Programming (Full Color)

Terry Griffin

Publisher Resources

ISBN: 9781593272180Errata