Communicating with Sounds
Students will learn to program different types of sounds.
Questions to investigate
How can sound help someone to communicate an idea?
Check to make sure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.
There are many ways to communicate with each other. Allow students to share some ways that they frequently communicate.
Engage students in a challenge to communicate without talking or writing/texting.
Students will explore how to program sounds.
Each partner in the team will need a matching set of three bricks of three different colors.
- Ensure that each student in the pair has the same three colors bricks.
- Partner A will stack the three bricks in any order. For example, if the student’s bricks are green, red, and blue, then the stack might be green on the bottom, red in the middle, and blue on top.
- Partner A should communicate to Partner B how to build the stack without talking. The simplest approach here would be to show Partner B how to build the stack.
Next, challenge the students to repeat the exercise with Partner B creating the stack. However, this time students cannot show the stack to each other.
- Ask the teams to come up with a way to communicate with each other using sounds.
- Demonstrate the idea by saying that the green brick is represented by a clap, the red brick by a snap, and the blue brick by a stomp.
- Make each sound as you create your stack.
- Students should create their own sounds for each brick and try to work together to build the stacks.
Discuss with students how sound can be used to communicate other than talking. Examples may include whistles or honking a horn to get someone’s attention, clapping hands to show approval, or a scream that means you are very scared of something.
Creating sounds is a great way to communicate.
Investigate producing beep sounds on the hub.
Direct students to open a new project in the Python programming canvas. Ask students to erase any code that is already in the programming area. Students should connect their hub.
Allow students to investigate how sounds can be made using the hub with this sample program.
Provide students with the sample code below. Have students type the code into the programming canvas.
Students can also copy and paste the sample code from the Knowledge Base Getting Started Part 1: Programming Simple Outputs.
# Import the PrimeHub class from spike import PrimeHub # Initialize the Hub hub = PrimeHub() # beep beep beep! hub.speaker.beep(60, 1)
Review the code with students to identify what sections of the code tell the software what to do (importing the hub), what portions of the code tell the hub what to do (initialize and beep), and what portions are just notes to the programmer (# green sections).
Ask students to identify areas that they could change to play different sounds. Encourage students to try different numbers.
Allow students to share the new sounds they have created by changing the numbers. Ask students to identify what the number 60 and the number 1 each represents in the code. Explain that the number 60 represents tone (low or high pitch) and the number 1 represents the length of time it plays.
Ask students to replace the number 60 (tone) with a number lower than 44. Discuss what happens.
Note: Students may have already discovered this on their own. Discuss as it becomes relevant.
# Import the PrimeHub class from spike import PrimeHub # Initialize the Hub hub = PrimeHub() # beep beep beep! hub.speaker.beep(40, 1)
Students will encounter an error, which can be identified by a red flashing light on the hub or an error message in the console.
- Ask students to explain what happened. This represents an error which can occur if the information is not inputted correctly. The allowed range of tone is 44-123. Anything outside this range will provide an error.
- Remind students that this error message will remain in the console. Any new message will appear after this one.
Play a Song
Challenge students to take what they learned in their investigation to add additional lines of code to create a song. Students should add several additional lines of code with different sounds to make a song.
Guide students to reference the sound options through the Speaker section in the Knowledge Base and select beep(). This guide will provide a range of numbers to use in the code to make different sounds as well as some guidance on errors. Allow students time to explore changing the images shown as time allows.
Here is a sample song for students that might struggle.
> # Import the PrimeHub class > from spike import PrimeHub > # Initialize the Hub > hub = PrimeHub() > # Here is a new song > hub.speaker.beep(60, 0.5) > hub.speaker.beep(67, 1.0) > wait_for_seconds(0.5) > hub.speaker.beep(60, 0.5)
Allow students to share their final song programs with each other and explain what their code shows.
Ask them questions like:
- What libraries need to be imported?
- How did you add additional lines to your code?
- What does each line of code in your program represent?
- What was challenging about this task?
- Where did you run into errors in programming? How did you fix or debug them?
Explain to students that the numbers included in the beep code are a float type because they can be whole numbers or include decimals. For example, the seconds could be set for 1.5 to be more exact.
Investigating playing pre-recorded sounds.
Explain to students that in addition to playing beeps, the hub can also be programmed to play pre-set sounds such as a cat’s meow or a dog barking. Have students look at the code they have been working with and consider how to change this code to play a pre-set sounded hub rather than just a beep.
Students should recognize that they will still need to import and initialize the hub. However, students should recognize that they will not need to code a beep sound. Instead students will need to know what pre-set sounds are available. Prompt students to think about where they might locate the pre-set sounds. Students can access these later.
Ask students to create a code investigate how sounds can be made using the sample program provided in the Knowledge Base Getting Started Part 1: Programming Simple Outputs in the Playing Sounds section. Prompt students to either copy this code to the programming canvas or type it in by modifying their existing project.
> \# Import the PrimeHub class > from spike import App > \# Initialize the app > app = App() > app.play_sound('Cat Meow 1')
Troubleshooting tip: Ensure students are bringing in the proper libraries to program both parts of the challenge. For additional debugging information, reference the Knowledge Base.
Note: Because the sounds are coming from the device and not the hub, ensure the speakers on the device are turned on.
Discuss with students what is different about this code than the code for playing beeps. Students should see that the sounds are based on names and not numbers.
Discuss with students what each line of the code represents. The app=App() line is referencing the functions within the app whereas play_sound sets the variable that you are selecting from the sound library.
Additionally, students should recognize that the sound is coming from their device (app) and not the hub. Prompt students to think about why. When they import Speaker, it allows the beeps to be heard. When they import App, it allows sounds to be heard through the device.
Ask students why they think a “1” is located after the words cat meow. In this case, the 1 is to differentiate between other similar sounds Cat Meow 2 and Cat Meow 3. The number is part of the string or name for that variable. Ask students if they remember what a string is. You may need to review this term.
Allow students to try other sounds by changing the code from ‘Cat Meow 1’ to ‘Triumph’ or ‘Doorbell1”. Prompt students to reference the App section in the Knowledge Base and select play_sound() to locate the sounds library.
Challenge students to try different sounds from the library of options provided to create a pattern. Allow students to share their sounds with other groups.
Discuss with students how they can use sounds to communicate in a variety of ways.
Discuss the program with students. Ask students questions like:
- How does programming beeps differ from programming sounds?
- Where do you hear the sound when the beep plays?
- Where do you hear the sound when the sound plays?
Have students answer the following in their journals:
- How can you use beeps and sounds to communicate?
- What characteristics of a good teammate did I display today?
- Ask students to rate themselves on a scale of 1-3, on their time management today.
- Ask student to rate themselves on a scale of 1-3, on their materials (parts) management today.
- Describe the function of hardware and software.
- Program sounds and beeps and learn how to debug a simple program.
- Create a sound pattern.
- SPIKE Prime sets
- Device with SPIKE App installed
- Student journal
Design projects that combine hardware and software components to collect and exchange data.
Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
Incorporate existing code, media, and libraries into original programs, and give attribution.
2-AP-19 Document programs in order to make them easier to follow, test, and debug.
Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 8 topics, texts, and issues, building on others' ideas and expressing their own clearly
Present claims and findings, emphasizing salient points in a focused, coherent manner with relevant evidence, sound valid reasoning, and well-chosen details; use appropriate eye contact, adequate volume, and clear pronunciation
Follow precisely a multistep procedure when carrying out experiments, taking measurements, or performing technical tasks
Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases; gather vocabulary knowledge when considering a word or phrase important to comprehension or expression