You must first complete Playing A Beep before viewing this Lesson

Looping Through Sounds

Introduction

We will now start making a basic loop of two sounds!

Components Needed

  • Little Python Brain
  • A tablet/phone/laptop
Steps

1

Coding the second sound

We will start by duplicating the bz.playNote blocks we made on the previous lesson. Simply change the note of this one to c5.

2

Using the Loop block from Basics

Remember the while True block from before? We will use an alternative looping block in this project. From the Basics category, get the Loop block. The only difference between these two is that:

  • the while True block will repeat forever until we interrupt it with Ctrl+C. Breaking out of the loop and ending the code. However, if we interrupt the code while it’s playing a note on the buzzer, then the buzzer will keep on playing that note forever!
  • the Loop block can be ended by holding the LP button on the Little Python Brain. By ending the loop this way, this makes sure that it ends the code when it’s not playing a note!

 

3

Completing the Loop

Drag the playNote blocks inside the Loop block and we’re good to go!

The Complete Code

Back to: Beginner > Police Siren

CONTACT US

    Log in with your credentials

    or    

    Forgot your details?

    Create Account