Book Image

Scratch Cookbook

By : Brandon Milonovich
Book Image

Scratch Cookbook

By: Brandon Milonovich

Overview of this book

Scratch 2.0 is an easy to use programming language that allows you to animate stories and create interactive games. Scratch also gives you the capability of using programming to calculate complicated calculations for you. Scratch Cookbook will lead you through easy-to-follow recipes that give you everything you need to become a more advanced programmer. Scratch Cookbook will take you through the essential features of Scratch. You'll then work through simple recipes to gain an understanding of the more advanced features of Scratch. You will learn how to create animations using Scratch. Sensory board integration (getting input from the outside environment) will also be covered, along with using Scratch to solve complicated and tedious calculations for you. You'll also learn how to work through the exciting process of project remixing where you build on the work of others. Scratch Cookbook will give you everything you need to get started with building your own programs in Scratch that involve sounds, animations, and user interaction.
Table of Contents (17 chapters)
Scratch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Integrating the sound sensor


The sound sensor can be a useful tool in getting your program to interact with the outside environment.

Just like the other blocks we've used so far, the sound returns a value between 0 and 100. It is simply a measure of how loud the area around the sensor is, and it is not a microphone.

Getting ready

In this recipe we are going to explore the sound sensor by making the cat make a meow sound when a loud noise is detected by the sensor. To prepare for this, all you need to do is open a new Scratch file.

How to do it...

Here are the steps we'll need to get this going:

  1. Drag over a block.
  2. Similar to the forever loop we've used before, we can also use the forever if loop. Drag it into the sequence.

  3. Under the Operators category, drag over a () > () block into the conditional spot of the forever if loop. (Note that in Scratch 2.0 this loop doesn't exist, and we build it using the forever loop and if statement.) You should have this code now:

  4. Within the first open spot...