VR - Mission 6: Robot Metronome
Robot Metronome
Students build an interactive metronome that flashes LEDs and plays a tone in time, then add a toggle for sound and a list of selectable tempos.
Overview
Mission 6 combines loops, branching, Booleans, and lists into one project: a working metronome. Students start by flashing the user LEDs and playing a tone once per second, then use an equation to calculate timing, add an if statement to control the sound, and use the 'not' operator to toggle sound on and off with a button. From there, students use a bit-shift operator to light up individual LEDs and build a list of five tempos that wraps around when a button cycles past the end of the list.
π― Mission Goal: Students create an interactive metronome with LED indicators, sound, and tempo selection.
Learning Targets
- I can create a simple metronome by flashing all user LEDs and playing a tone, once per second.
- I can update a variable using a mathematical equation.
- I can use an if statement to control program flow.
-
I can use the logical operator
notto toggle a Boolean variable. - I can use a bit-shift operator to control LEDs.
- I can define and use a list of tempos.
- I can wrap around an index variable to start over when the length of the list is reached.
Key Concepts
- Infinite while loops are used to execute an algorithm continuously.
- Iterating with a while loop or a for loop reduces the need for repeated code.
- Both loops are versatile and can iterate forward or backward.
-
Branching with an
if:statement controls the flow of the program. - A Boolean variable can be used as a toggle, or on/off switch.
- A bit shift operator is used to change which LED lights up.
- A list can hold multiple values.
- Each item in a list is in order and is accessed using an index.
- The state of a button press is True or False and can be used to control the CodeBot.
Assessment Opportunities
- Quiz after Objective 4
- Quiz after Objective 8
- Submit program code, or give students printed code and have them explain each line: Objective 4, Objective 7
- Give extra practice with logical operators
- Give extra practice with lists
- Code Tracing Chart as a debugging tool
-
Submit final
metronome.pyprogram - Level-1 Mission 6 Review Kahoot!
Success Criteria
- Use a while loop to flash LEDs
- Use two for loops to flash LEDs
- Use an infinite loop to flash LEDs continuously
- Toggle a Boolean variable to control sound and the power LED
- Use a list for five tempos
- Wrap around the list for continuous selection
Digital Resources
- βΈLevel-1 Mission 6 Assignment
- βΈLevel-1 Mission 6 Assignment Answers
- βΈLevel-1 Mission 6 Review Questions
- βΈCode Tracing Chart
- βΈLevel-1 Mission 6 Review Kahoot!
- βΈMission 6 Obj 3 Code Solution
- βΈMission 6 Obj 4 Code Solution
- βΈMission 6 Obj 7 Code Solution
- βΈMission 6 Obj 8 Code Solution
- βΈMission 6 Final Code Solution
Classroom Materials
- βΈComputer or Chromebook with internet access
Real-World Applications
The concepts in this lesson show up in real-world technology all the time: continuous looping, LEDs as indicators, lists, and toggles for on/off. Challenge students to come up with their own examples of each.
Extensions & Cross-Curricular
π€
Vocabulary
βΎ
sleep(). Common functions for checking the current elapsed time are time.time() and time.ticks().
π
New Python Code
βΎ
not operator.
len() function returns the number of items in a list.
π
Standards
βΎ
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
Certiport IT Specialist: Python Standards
PCEP: Certified Entry-Level Python Programmer
- Review Mission 3's binary LED pattern before Objective 1 - the first objective uses a similar pattern to turn on all user LEDs.
- Review Mission 4's speaker and tone code before Objective 2, as needed.
-
Review the difference between
=and==before students start writing conditionals.
- When an infinite loop is used, the program will not stop automatically - it must be stopped manually by pressing the STOP button.
- There is a lot going on in this mission. Take your time and don't rush through the objectives.
- Create worksheets or extra activities as needed to review throughout the objectives - extra practice with logical operators and with lists is suggested in Assessment Opportunities.
Lesson Outline
Have students write or discuss their answers before revealing them.
- Question: What is a real metronome used for, and how does it keep a steady beat?
- Question: Why would a loop that never stops on its own be useful in a program?
Students flash all user LEDs in a binary pattern and play a tone, reviewing techniques from Mission 3 and Mission 4, to build one beat of the metronome. They then wrap that beat in an infinite while loop so it runs continuously, once per second, and use an equation to calculate the pause between beats.
Students add an if statement so the speaker only plays a tone when a Boolean variable is True, introducing branching and control flow. Have students submit their code, or hand them printed code to explain each line.
= and == here if students mix them up.Give the quiz after Objective 4.
Students use a button and the not operator to toggle the sound_on Boolean, then use the opposite of that Boolean to control the power LED as a visual on/off indicator.
Students use a bit-shift operator to light up a single line sensor LED based on an index variable, previewing how the tempo selection will be displayed. Have students submit their code, or hand them printed code to explain each line. They then define a list of five tempos, use the index variable to select a tempo from the list, and add a wrap-around check so the index resets to 0 after the last item in the list.
Give the quiz after Objective 8.
Students combine the flashing LEDs, tone, sound toggle, and tempo list into one complete metronome program. Have students submit their final "metronome.py" program.
Use an extension or cross-curricular activity as a post-mission activity.
Wrap up with the Level-1 Mission 6 Review Kahoot!, which covers all Mission 6 objectives.