One of the simplest things that we can do, to make something cool with our robot, is the “Play note” command. One note is just one note, but put the right notes together in the right order and we have a masterpiece. Let’s get started:
First, let’s play a note. Any note.
I drag and dropped this block into the programming area. And then I clicked it. And there was music. Well, calling it music is a stretch of the imagination, but it played a note. So, I added another note.
When I drag the second blog below the first block, the bottom of the first block turns white. This means when I “drop”, they will fit together. I can also change the length and pitch of the note. Here, I am changing the length of the second note:
Ok, now I want more notes. For more notes, I need more of the same “play tone on….” block. A shortcut I can make, instead of dragging and dropping is to copy and paste. If I right click on the blocks on the programming area, it gives me a menu:
Selecting “duplicate” copies the blocks. Note that this will duplicate all the blocks below and including the block I clicked. So if I had clicked the bottom block, only one block would have been duplicated. As I clicked the top block, both blocks were duplicated:
Now, I can add them to the end of my song:
And keep developing:
Ok. Now, I want to have a pause. So I need a different block. I need to wait. Under the “Control” Scripts, there is a “wait” block:
I am going to add that to the end of my song, then repeat the first half with a couple of changes:
One important aspect of writing code is including comments. While they don’t affect how a program runs, they are a huge help to people who read the code. This could be other people who are working on the same team as you, or you yourself, months after having initially written the code (and having forgotten some of the details). Comments should be included in all programs to guide those reading it. To add comments, right-click on the block you want to add the comment to and then select “add comment”:
Here I have added comments to my song:
Make sure that you add comments to all your programs, and update the comments where necessary if you make any changes to programs.
- Do you know what the song is? Can you finish the song? Can you amend the comments to reflect the updated status?
- Can you write the song “Merry Christmas”? Be sure to add comments
- Can you write your own song? Add comments
Construct Your Dreams!