Make a little song-order machine, which will play different songs when different switches are pressed.
Suitable kits: mCookie202, mCookie302, IBC
- USB cable*1
- Sensor cable*3
- Sensor shell*1
- Lego or other fixation structure
- Assemble modules and sensors:
- Stick the red core module, battery base and green extension module together;
- Connect the buzzer to pin 6/7 of Hub;
- Connect the two crash sensor to pin 2/3 and 4/5 of Hub respectively;
- Insert one end of USB cable into USB upload module, and connect the other to computer;
Required Program Blocks
Judge which crash is pressed with "if-do" condition statement, and play the corresponding song,and continue to judge after playing.
1. Press the crash of pin 4, an it will start to play the song "Doraemon".
With "if-do", "crash sensor", "buzzer on-song" program block, modify the pin number as the diagram shows, and choose song "Doraemon" or other songs.
2. Press the crash of pin 2, and it will start to play the song "Calabash Boys".
With "if-do", "crash button", "buzzer on-song" program block, modify the pin number as the diagram shows, and choose the song "Calabash Boys".
Test the result
After upload the program, press the crash of pin 4, an it will start to play the song "Doraemon"; press the crash of pin 2, and it will start to play the song "Calabash Boys". In this way, our little song-order machine is completed! Of course, you can also choose other songs to play.
- The product number of buzzer:
- The buzzer is of passive buzzer type.
- For details, please refer to Sensor-Buzzer.
- Q: Why does the buzzer not produce a sound when connect it directly to the power supply?
- A: Because the buzzer is one kind of passive buzzer, which can only ring with changed voltage signal. The active buzzer can ring after added with voltage.
- Q: Can the buzzer sing?
- A: It can produce do, re, mi, fa, sol, la, si tones of different frequencies, which can make up music. You can refer to Music Painting. If you want to play the music, an audio decoding chip and horn is essential.
- Q: Why can't we choose songs when it is playing the music? And we can only choose when it ends up playing.
- A: Because the "buzzer on-song" program block integrates the code, with internal procedures, it will only execute other control commands after executing the song.