Lab 5: Midterm 1, and lists

In lab today you will first take the in-lab portion of midterm 1 for 20 minutes, followed by a microbit activity.

In-lab portion of Midterm 1

The in-lab portion of midterm 1 is at Zybooks 5.41: Midterm 1 in lab and will be available for 20 minutes starting at 3pm on Tuesday, 2/7. Only work on the material below after you've finished the midterm 1 in-lab portion. No late work will be accepted.

Microbit Activity: Storing notes on lists

Today we will play a tune by storing the note frequencies on a list and playing them one at a time. Write your name down to join a group in today's lab collaborative google slides document.

Background: A google search on: microbit note frequency chart can show you which musical note letter (C D E F G A B C) corresponds to which frequency, with a chart such as the one at right. Select at least the first 6 notes of some song. If you can't think of one, you can use "Happy Birthday to You" which has the notes shown at right.

We will be using the Music drawer play tone block.


The blocks at right represent te first 6 notes of "Happy Birthday to You". Viewing these blocks in Python code view looks like the equivalent Python code shown below, where the notes are represented by their frequency values:

music.play_tone(262, music.beat(BeatFraction.WHOLE))
music.play_tone(262, music.beat(BeatFraction.SIXTEENTH))

music.play_tone(294, music.beat(BeatFraction.WHOLE))

music.play_tone(262, music.beat(BeatFraction.WHOLE))

music.play_tone(349, music.beat(BeatFraction.WHOLE))

music.play_tone(330, music.beat(BeatFraction.DOUBLE))

To Do:

  1. Get the above sample to play on your microbit.

  2. Put all the frequency values into a list, using the list to play the song instead of individual blocks. To do this:

    1. Open up the Advanced menu option near the bottom of the Microbit drawers. (See right)

    2. Select the Arrays option and select the set list to... block. Use the pull-down arrow to name your list song1.

    3. Within the song1 list store the frequency notes for the first set of notes of your song (e.g. the values 262, 262, 294, 262, 349, 330 in Happy Birthday shown above). Initialize this list as indicated above when the program starts.

    4. Select the block on button A pressed.

    5. Inside that block create a while loop that uses counter as the counting variable. Inside the while loop:

      1. Use the Music drawer play tone block. Rather than explicitly indicate a particular note to be played inside the play tone block, we will instead use one of the values stored in the song1 list. In that spot use the array drawer get value at block to refer to the song1 list, retrieving the (counter) entry note.

      2. Increment the while loop counter by 1


Don't forget to paste your code onto your group's google slide, so we can give you credit for it.