During the FIRST LEGO League competition you can hardly use the sound block, because of the noise from the excitement around the tables, but it has a few interesting applications. I this video lesson I will show you how to use the sound block and build a program that makes the robot say which color it sees.
- 12 May 2013
Basic NXT Tutorials
- download the source of a program that tells the color the robot is seeing.
In this video I will cover the next block in the Action subpalette - the sound block. I will comment on it's adjustments and on few of its applications. During the competition you can hardly use the block, because of the noise from the excitement around the tables, but it has a few interesting applications. Today I will show you how to build a program that makes the robot says which color does it see.
The sound block
The most common application of the sound block, I have seen is for debugging your program. You can put a sound block specific place in your program in order to see what is actually happening and eventually fix your program. It is more convenient than the display block, because you do not have to get down to see what is displayed. But now let's get back to the block. You can play a sound file with it. For instance you can make the robot say fantastic or you can play a tone and choose which tone to play and for how many second to play. Then you can make the robot play the sound or stop the sound if it is playing a sound at that moment and you can control the volume of the sound. There is also an option to wait for completion or not. If it is checked the program will go to the next block after the sound is played and if it is not, the program will go on the next block and simultaneously with the next block will play the sound. Now, let's make a simple program. Let's say I will wait until the enter button of the robot is pressed and then the robot will say “good job”. Let's download the program to the brick.
Video of the example
Now, when I press the orange button the robot should say “good job”. And it is working!
Making the robot user friendly
Now, let's make the robot say, what color does it see. For this purpose we will use the color sensor. It will return one if the color is black, 2 if the color is blue, 3 if the color is green, 4 if the color is yellow, 5 if the color is red and 6 if it is white. Then I will use a switch block. Choose not flat view, value and I will choose number. I will add cases until we reach six. So the default I will leave blank. If the value is one I will take sound block and choose the sound black and set the volume to 100. Then if it is two again I will take a sound block, make the volume one hundred and choose the sound blue. If it is three I will set the sound to green. If it is four I will set the sound to yellow, if it is five I will set the sound to red and if it is six I will set the sound to white. Now, all of this I will put in a loop and then I will download the program to see how it works.
Video of the program
I will use the book from the mindstorms education series and open it to the last page, where are the colors and I will show different colors to the color sensor. So yellow, red, green, blue, black and white.