Spybots Smart Parts  
  The Unofficial Resource Centre for Lego Spybotic  
   
img  
   
   

TUTORIALS

TUTORIALS

BASIC

making noise - nqc

Tutorial Details:
Difficulty Level: Basic
Topics Covered: Playing sounds using NQC.
Assumed Knowledge: THe Basics, My first program
Written By: BILL LANE

Print Version

Spybot's are capable of an incredible range of sounds. They have 64 pre-programmed sounds that can be called by number and room for an additional 16 user defined sounds (maximum size 63 bytes each). We won't be looking at defining our own sounds today. Instead we'll just look at making sounds and using those 64 pre-programmed sounds.

Let's start with the pre-programmed sounds. If you take a look in globals.h (it's in Spybot/include) you'll find that someone has gone to the trouble to provide names for each of the 64 sound sequences. For this example we can use the names as a guide use the numbers to make the sounds. So here's an example program:

task main()
{
PlaySound(41);
Wait(540);
}

This will play sndDizzy. Note the use of wait so we can actually hear the sound before the program closes down. To play any of the available sound sequences just replace 42 with the relevant number download and enjoy. To stop the current sound you can use MuteSound(). Too easy really and I imagine you could create programs for the next 10 years without even thinking about making your own sequences. But you can create and play your own sequences using PlayTone. All you need to use PlayTone is to supply a frequency and a duration (in that order). Here's how:

PlayTone(440, 50);
wait (50);

Repeat these two lines with variations in frequency and duration and you and your Spybot can make beautiful music together. The documentation provides the following chart to assist would be composers.

 

G# 52 104 208 415 831 1661 3322  
G 49 98 196 392 784 1568 3136  
F# 46 92 185 370 740 1480 2960  
F 44 87 175 349 698 1397 2794  
E 41 82 165 330 659 1319 2637  
D# 39 78 156 311 622 1245 2489  
D 37 73 147 294 587 1175 2349  
C# 35 69 139 277 554 1109 2217  
C 33 65 131 262 523 1047 2093 4186
B 31 62 123 247 494 988 1976 3951
A# 29 58 117 233 466 932 1865 3729
A 28 55 110 220 440 880 1760 3520

 

This tutorial is protected by International Intellectual Property Rights laws and may not be reproduced or redistributed in full or part, without the prior written consent of the author. Unauthorized reproduction of this tutorial or its contents may result in prosecution.

 

 
 
DISCLAIMER: All content is provided as is, with no warranty stated or implied regarding the quality or accuracy of any content on or off this site. All trademarks, service marks, and copyrights are property of their respective owners. This site is not sponsored, authorized or sanctioned by the LEGO Group nor representative of their opinions in any way.PRIVACY POLICY