Raspberry_Pi_Education_Manual

Notes:

Import your sound effect from the Sounds tab. You’ll find it right next to the Scripts and Costumes tabs.

Now, let’s build our script. Before you start, select the “ lights ” sprite in the Sprites List.

First things first: we want to start with the lights out. So we use a green flag event to switch our lights sprite to “ costume1 ”, which shows three black lights.

As the train approaches the level crossing barrier, I have used an “when [ ] key pressed” block from Control to detect it, setting the value to “t”. This event will trigger the lights, alarm and barrier. But first, let’s deal with the alarm.

Build the script you can see in the screenshot above. This will cause the alarm to sound when the “t” key is pressed.

A beginner’s guide to Scratch

42

Made with FlippingBook flipbook maker