EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #71 background imageLoading...
Page #71 background image
Page 74
PlayTone(277, HALF);
PlayTone(330, GRACE);
PlayTone(311, HALF);
PlayTone(277, HALF); Wait (2HALF);
PlayTone(247, HALF);
PlayTone(311, HALF);
PlayTone(208, HALF);
PlayTone(208, 2BEAT);
Wait(GRACE + 5HALF + 2BEAT + HALF);
stop main;
Float(OUT_A + OUT_C);
}
When the sing task is done playing music, it stops the main task with the stop command. Then it turns the motors off. The order is critical. If we turned off the motors and then stopped the
main task, it's possible that main would turn on the motors again before it was stopped. Multithreaded programming is powerful but tricky.
Each RCX program can have up to ten tasks.
Subroutines
A subroutine is a group of commands that you will execute frequently. Subroutines offer a way to clean up your source code and reduce the size of compiled programs. Subroutines in NQC are
defined in much the same way as tasks. The following program has one subroutine, called wiggle(). The main task shows how this subroutine is called:
task main() {
wiggle();
Wait(200);
wiggle();
}
sub wiggle() {
OnFwd(OUT_A);
OnRev(OUT_C);
Wait(20);
OnFwd(OUT_C);
OnRev(OUT_A);
Wait(20);
Off(OUT_A + OUT_C);
}
Subroutines execute as part of the task from which they are called. It works just as if the call to wiggle() was replaced with the commands it contains. The nice thing about subroutines is that
their code is defined once, but you can call it as many times as you like from other places in your program. You could accomplish the same sorts of things with subroutines and macros, but
subroutines are more

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals