CHRISTOPHER HODDINOTT.COM
Menu

Sonic Pi - Lesson 2

8/11/2015

0 Comments

 
Learning Objective 

  • Understand that computers don’t know what to do with an error.
  • Write a simple program using text and identify any errors.
  • Iterate/repeat some code a number of times to create a 'bass line'.

Lesson Brief
  • A short exercise to recap the notion of statements and control flow within a program.
  • A debugging exercise.
  • Starting the Sonic Pi application.
  • Iteration as a repeating structure.
  • Syntax punctuating structure.


  1. With just one group acting and with the rest of the class watching, introduce the two error cardsinto the deck of computer program cards; shuffle them up and repeat the exercise described in the previous lesson. Observe what the pupil with the foreign language error card does, and then have a short discussion with the class about what perhaps should happen. Then point out that there’s another error card, but with a subtle error in the spelling. Explain that to the computer they are both as unintelligible as each other. The computer isn’t clever enough to read through the subtle error.

  2. The pupils are then separated into pairs and are given their own set of Sonic Pi equipment. Pupils follow the instructions to connect the various parts of the Raspberry Pi together and once it has booted, they start the Sonic Pi program by clicking on the menu item under start -> programming -> sonic-pi.

  3. Next, the pupils are given their first introduction to debugging. They are asked to type in the following one-line program which is incorrect: pllay 42. They are then asked to observe what happens when they run the program. At this point it’s important to emphasise that this is a typical situation for real programmers. It means that they have done something that the computer doesn’t understand; because the computer is not very clever, this is very easy to do. The students are invited to correct (debug) the program by removing the extra l. They are then asked to observe the output of the program.

  4. A selection of pupils are asked to form a line with the computational cards, and to act out the program as carried out in the previous lesson. The class is then asked how we can repeat this program twice. One of the answers might be to duplicate the line, forming a line twice as long as the original with the original sequence of statements duplicated twice. Now, ask the class to act out this new longer program. Once this has been completed ask how we might repeat the original program 10 times, or 100 times. What about 1000 times? Clearly, we’d run out of people!

  5. Introduce the iteration cards: 1.times, do and end. Wrap the original program in the do andend cards, and prefix everything with the 1.times card. Explain that this is just a long-winded way of doing the same thing as the original program. The new cards are extra syntax which should be thought of as the same as punctuation; capital letters, commas, full stops and so on. Like punctuation, this syntax helps the computer structure the program. However, with this extra syntax, we have actually formed a circle out of our code. The syntax defines the start and the end points of the loop: the do and end. In this case we only loop round the circle once, but if we replace the first card with 3.times we loop round our program 3 times. If you have enough space, try forming a circle and enact the loop. Explain that this loop structure is called iteration.Pupils are asked to enter the following ‘bass line’ code into the Sonic Pi application:
  • To Compose your BassLine
  1. Try this command to start you off. 
  2. play 42 sleep 0.5 play 45 sleep 0.85 play 54 sleep 1 play 54 sleep 0.7 play 45 sleep 0.2 play 49 sleep 1
  3. They are then asked to repeat this line 5 times. They do this by writing:

    5.times do play 42 sleep 0.5 ... rest of code ... sleep 1 end

  4. You can choose to play around with this, modifying it as they feel fit, for the remainder of the time. For the adventurous pupils, you can suggest that they nest the iterations; in other words, have one iteration inside another.

Use this link to help you. 
https://www.raspberrypi.org/learning/sonic-pi-2-taster/worksheet.md

Homework;

Write out your own Bass Line and submit it on the form below.

  • Create your own bass melody 
  • Change the synth 
  • Needs to repeat or loop

Submit your code here

http://goo.gl/forms/Bsta7cUN82

https://www.raspberrypi.org/learning/getting-started-with-sonic-pi/worksheet/


Any issues email MR Hoddinott


0 Comments

    Archives

    September 2015
    August 2015
    July 2015

    Categories

    All
    Lesson 1
    Lesson 2
    Lesson 3
    Lesson 4
    Lesson 5
    Project
    Sonic Pi

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • Home Page
  • About Me
  • LinkedIn
  • Extended Essay
  • Social Media
    • Pinterest
    • Twitter Feed
    • Mr Hoddinott's Awesome Music Video of the week
  • Contact
  • MLI
  • Contact
  • Home Page
  • About Me
  • LinkedIn
  • Extended Essay
  • Social Media
    • Pinterest
    • Twitter Feed
    • Mr Hoddinott's Awesome Music Video of the week
  • Contact
  • MLI
  • Contact