pxt-calliope/docs/lessons/happy-birthday/activity.md

57 lines
2.7 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# happy birthday blocks activity
2016-09-24 07:27:57 +02:00
Play sounds with music blocks.
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
Have you ever tried to play a song on an instrument? Let's try coding the song "Happy Birthday" on the @boardname@ !
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
Let's start by adding the code in the music drawer that includes a single musical chord (or pitched sound) with the `play` block. Then insert the chord "C". Once you are done coding, don't forget to run your code in the simulator or the @boardname@.
2016-03-26 00:47:20 +01:00
```blocks
2016-09-24 07:27:57 +02:00
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
2016-03-26 00:47:20 +01:00
```
* click run to see if the code works as expected.
We want to continue to adding musical chords with the `play` block. So insert the appropriate chord blocks: `D`, `F`, `G` to complete the first part of the song. Modify your code so that your code looks like this.
```blocks
2016-09-24 07:27:57 +02:00
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quarter));
2016-03-26 00:47:20 +01:00
basic.pause(100);
```
* click run to see if the code works as expected.
We want to continue to adding musical chords with the `play` block. Then insert the appropriate chords: `B`, `C`, `D`, `E` , `F` to complete the second part of the song. Modify your code so that your code looks like this.
```blocks
2016-09-24 07:27:57 +02:00
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quarter));
2016-03-26 00:47:20 +01:00
basic.pause(100);
2016-09-24 07:27:57 +02:00
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quarter));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quarter));
2016-03-26 00:47:20 +01:00
basic.pause(100);
```
* click run to see if the code works as expected.
### ~avatar boothing
2016-04-13 17:27:45 +02:00
Excellent, you're ready to continue with the [challenges](/lessons/happy-birthday/challenges)!
2016-03-26 00:47:20 +01:00
### ~