CyberPi: Voice Reactive Lights
In this lesson, students will create a code to change the lighting effects based on sound levels. They’ll use this information to display bar charts on the screen as well.

Lesson
Overview
Description
In this lesson, students will create a code to change the lighting effects based on sound levels. They’ll use this information to display bar charts on the screen as well.
Objectives
Display a bar chart on the screen.
Change lighting effects and bar chart based on the sound levels.
Use mind maps to analyze how to complete a project.
Write programs to complete the Voice Reactive Lights project.
Before the Lesson
Preparation
For the teacher and students:
Computer with mBlock 5 installed from here: https://www.mblock.cc/en/download/ or mBlock Web version
Wi-Fi connection to student devices for IoT connectivity
One CyberPi’s with USB-C cable
Pocket shield (optional)
Example program(s): CyberPi – Lesson 2 - Voice Reactive Lights
For students:
Proficiency in block-based coding
How to collect data with CyberPi's sensors
Review
Warm Up
Objective:
Show pictures and play videos to demonstrate how to apply lights and sounds in a show.
Procedures:
Have students search for and compare traditional fountains and musical fountains.
Have students answer the questions: Which type of fountains do you like? Why?
Introduce the working principles and characteristics of musical fountains:
Music, lights, and fountain are programmed to react to each other.
The lights and fountain are programmed to react to the music
Have students answer the question: How do the music, fountain, and lighting fit together?
Conclude the following:
Louder music means ① lights in a darker color, ② higher spout, and ③ faster changes in shapes.
Softer music means ① lights in a lighter color, ② lower spout, and ③ slower changes in shape.
Direct Instruction
Tour of mBlock 5
1. Open the mBlock software or mBlock 5 Web version.
2. Introduce students to the following key areas of the software interface:


Connect the CyberPi
3. Plug the CyberPi into the computer using the included cable. The CyberPi should boot up and the screen will display either the last program uploaded or the Home menu.
4. On the "Devices" tab in mBlock, click the "Add" button. Select CyberPi and click "Ok".
5. Click the "Connect" button. Then, select the USB port and click "Connect".

6. If connected successfully, the button will change to "Disconnect".

Guided Practice
Hands On
Objective:
Focus on the interaction between sound, light, and fountain, and prepare students for the Elaborate section.
Procedures:
Tell students: Though we can’t make musical fountains, we can use CyberPi to make Voice Reactive Lights.
Analyze with the students what features the project has and draw a mind map.

Independent Practice
Try It
Objective:
Give students the freedom to explore further so that they can enhance their programming skills.
Procedures:
Remind students that they need to connect the device to the computer and select Upload mode.
Recap what hardware components CyberPi has and demonstrate how to detect sound level with the sound sensor.
Design lighting effects:
Tell students: To change the lighting effects, we need these coding blocks.

Say: We’ve learned that we could use the volume to decide the lighting and other effects. So, why don’t we try using the sound sensor to detect the sound level?

NOTE:
To have lighting effects randomly produced, use pick random ( ) to ( ) to set the RGB values.
To ensure a seamless transition between different light effects, use wait ( ) seconds.(Instruct students to include the wait block in the program, then remove it, and compare the results.)
The lighting starts changing as soon as the program runs.
Design what to display on the screen:
Use chart-related blocks to show the sound levels on the display.

NOTE:
To draw more bars, use more blocks.
Use different colors to distinguish bars. If you set different bars to the same color, then all the data will be shown in the same bar. Look at the script below:

If we run the script above, a white bar and a red bar appear on the display. Every time this script is run, the white bar goes up to 50 first then falls to 10 while the red bar stays at 50 all the time.
To make volume bars with different heights, collect volume data at specific intervals.
To collect volume data, write the script below:

To continuously display sound levels, write a script as shown:

NOTE:
1. Instruct the students to do the following:
make a volume bar
make two bars with the same height
use variables to make bars with different heights
make four volume bars with different heights
2. To make the volume bars more dynamic, keep the intervals short.
3. CyberPi starts drawing bars as soon as the scripts are executed. So, the lighting effect script and volume bar script should both start with the same Event block.
Extension
Have students test their program by playing their favourite song and observing the graph changing
Have students use the line chart blocks instead of the bar chart blocks
Wrap Up
Wrap-Up & Quick Check
Objective:
Play some music and invite students to present their projects.
Procedures:
Play music and invite students to present their projects.
Divide students into groups and have them present the projects to their group members.
Invite volunteers to present their projects in front of the whole class.
Downloadable Materials
Example Program
Educational Standards
ISTE
ISTE
5b: Students collect data or identify relevant data sets, use digital tools to analyze them, and represent data in various ways to facilitate problem-solving and decision-making.
CSTA
CSTA
2-CS-02: Design projects that combine hardware and software components to collect and exchange data.
2-AP-11: Create clearly named variables that represent different data types and perform operations on their values.
Alberta - Grade 7-8 - CTF
Grade 7-8
CTF
Planning, creating, appraising and communicating in response to challenges.
Working independently and with others while exploring careers and technology.
British Columbia - Grade 7-8 - ADST
Grade 7
ADST
• Generate potential ideas and add to others’ ideas
• Identify and evaluate the skills and skill levels needed, individually or as a group, in relation to a specific task, and develop them as needed
• Select, and as needed learn about, appropriate tools and technologies to extend their capability to complete a task
Grade 8
ADST
• Generate potential ideas and add to others’ ideas
• Make a plan for production that includes key stages, and carry it out, making changes as needed
• Identify and evaluate the skills and skill levels needed, individually or as a group, in relation to a specific task, and develop them as needed
• Select, and as needed learn about, appropriate tools and technologies to extend their capability to complete a task
Manitoba - Grade 7-8 - Science
Grade 7
Science (Overall Skills and Attitudes)
7-0-4a Carry out procedures that comprise a fair test. Include: controlling variables, repeating experiments to increase accuracy and reliability
7-0-4c Work cooperatively with team members to carry out a plan, and troubleshoot problems as they arise.
Grade 8
Science (Overall Skills and Attitudes)
8-0-4a Carry out procedures that comprise a fair test. Include: controlling variables, repeating experiments to increase accuracy and reliability
8-0-4c Work cooperatively with team members to carry out a plan, and troubleshoot problems as they arise.
New Brunswick - Grade 7-8 - Science
Grade 7-8
Science (Attitude Outcome)
425 show a continuing curiosity and interest in a broad scope of science-related fields and issues
430 persist in seeking answers to difficult questions and solutions to difficult problems
431 work collaboratively in carrying out investigations, as well as in generating and evaluating ideas
Newfoundland & Labrador - Grade 7-8 - Science
Grade 7-8
Science
GCO: Skills - Students will develop the skills required for scientific and technological inquiry, for solving problems, for communicating scientific ideas and results, for working collaboratively, and for making informed decisions.
Nova Scotia - Grade 7-8 - Mathematics & Technology
Grade 7
Mathematics
PR05 Students will be expected to evaluate an expression given the value of the variable(s).
Performance Indicator:
PR05.01 Substitute a value for an unknown in a given expression and evaluate the expression.
PR02 Students will be expected to create a table of values from a linear relation, graph the table of values, and analyze the graph to draw conclusions and solve problems.
Performance Indicators:
PR02.01 Create a table of values for a given linear relation by substituting values for the variable.
PR02.02 Create a table of values, using a linear relation, and graph the table of values (limited to discrete elements).
PR02.03 Sketch the graph from a table of values created for a given linear relation, and describe the patterns found in the graph to draw conclusions (e.g., graph the relationship between n and 2n + 3).
PR02.04 Describe, using everyday language, in spoken or written form, the relationship shown on a graph to solve problems.
PR02.05 Match a given set of linear relations to a set of graphs.
PR02.06 Match a given set of graphs to a given set of linear relations.
Technology
GCO1: Students will be expected to design, develop, evaluate, and articulate technological solutions
GCO2: Students will be expected to operate and manage technological systems
Grade 8
Mathematics
PR01 Students will be expected to graph and analyze two-variable linear relations.
Performance Indicators:
PR01.01 Determine the missing value in an ordered pair for a given equation.
PR01.02 Create a table of values by substituting values for a variable in the equation of a given linear relation.
PR01.03 Construct a graph from the equation of a given linear relation (limited to discrete data).
PR01.04 Describe the relationship between the variables of a given graph.
SP01 Students will be expected to critique ways in which data is presented.
Performance Indicators:
SP01.01 Compare information provided for the same data set by a given set of graphs, including circle graphs, line graphs, bar graphs, and pictographs, to determine the strengths and limitations of each graph.
SP01.02 Identify the advantages and disadvantages of different graphs, including circle graphs, line graphs, bar graphs, and pictographs, in representing a given set of data.
SP01.03 Justify the choice of a graphical representation for a given situation and its corresponding data set.
SP01.04 Explain how the format of a given graph, such as the size of the intervals, the width of the bars, and the visual representation, may lead to misinterpretation of the data.
SP01.05 Explain how a given formatting choice could misrepresent the data.
SP01.06 Identify conclusions that are inconsistent with a given data set or graph, and explain the misinterpretation.
Technology
GCO1: Students will be expected to design, develop, evaluate, and articulate technological solutions
GCO2: Students will be expected to operate and manage technological systems
Ontario - Grade 7-8 - Mathematics
Grade 7
Mathematics
Algebra
C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves events influenced by a defined count and/or sub-program and other control structures
Grade 8
Mathematics
Algebra
C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves the analysis of data in order to inform and communicate decisions
Prince Edward Island - Grade 7-8 - Science
Grade 7-8
Science
GCO: Skills - Students will develop the skills required for scientific and technological inquiry, for solving problems, for communicating scientific ideas and results, for working collaboratively, and for making informed decisions.
Quebec - Grade 7-8 - Science
Grade 7-8
Science (Strategies)
Exploring various ways of solving the problem
Exchanging information
Comparing different possible explanations for or solutions to a problem in order to assess them (e.g. full-group discussion)
Saskatchewan - Grade 7-8 - Science
Grade 7-8
Science (Goals)
Develop Scientific and Technological Skills – Students will develop the skills required for scientific and technological inquiry, problem solving, and communicating; for working collaboratively; and for making informed decisions.
