This project will teach you how to create a piano in Scratch
Duration: 8-10 mins
Programming Language: Block-based programming
What you will need:
- An account in Scratch (sign up here)
- A laptop/desktop
Part 1: Design
Our end goal is to create 8 rectangles that will represent the piano keys like the picture below.
Each shape is a sprite, to create one, hover over the the cat logo on the bottom right corner of the screen and press
This will direct you to the costumes tab of the Sprite where you can draw whatever you want, for this project, we want to draw a rectangle.
- Choose the color you want inside of the rectangle to be
- Choose the color of the outline of the shape
- Click on the Square shape to easily draw the rectangle
- Use the second pointer button to resize the shape.
Once you’re done with the first shape, you can easily make the remaining 7 shapes by
- Right clicking on your mouse and pressing DUPLICATE
- You can then change the color of the shape
Part 2: Code
Once you have all 8 sprites, you can move one to code each sprite one by one. To find the piano sound,
- Go to CODE tab
- Click on the bottom left corner to find the music extension
- Click on music to get instrument sounds
Each sprite will have a similar set of codes.
- Click on the sprite you want to add the codes to
- Go to events and look for the block “when 1 key pressed“ (this will be the trigger)
- Go to music and drag the block “play note 60 for 0.5 beats“ underneath the event block
Continue with the rest of the sprites with the code in the picture below
You can also watch and code along with our instructor here and you can also pin it below!