Page 84 - The Unofficial Guide to Lego Mindstorms Robots
P. 84
73
start taskname
This command starts the named task.
stop taskname
Use this command to stop the named task.
The following program controls its outputs from main and uses another task, sing, to play some music. The sing task has
to be started from main; otherwise, its comm ands will never be executed.
task main() {
start sing;
while (true) {
OnFwd(OUT_A);
OnRev(OUT_C);
Wait(100);
OnFwd(OUT_C);
OnRev(OUT_A);
Wait(100);
}
}
#define SIXTH 12
#define HALF 3∗SIXTH
#define BEAT 2∗HALF
#define GRACE 6
task sing() {
PlayTone(330 , 2∗BEAT);
Wait(2∗BEAT + 2∗SIXTH);
PlayTone(115, SIXTH);
PlayTone(208, SIXTH);
PlayTone(247, SIXTH);
PlayTone(330, S IXTH);
PlayTone(311, 2 ∗BEAT);
Wait(4 ∗SIXTH + 2∗BEAT + 2∗SIXTH);
PlayTone(115, S IXTH);
PlayTone(2 08, S IXTH);
PlayTone(247, SIXTH);
PlayTone(311, SIXTH);
PlayTone(277, 3∗BEAT);
Wait(4∗SIXTH + 3∗BEAT + HALF);
PlayTone(277, HALF);
PlayTone(311, HALF);
PlayTone(370, GRACE);
PlayTone (330, HALF);
PlayTone(311, HALF); Wait (2∗HALF);
PlayTone(277, HALF);
PlayTone(330, HALF);
PlayTone(220, HALF);
PlayTone(220, 2∗BEAT);
Wait(GRACE + 5∗HALF + 2∗BEAT + HALF);
PlayTone(247, HALF);