pxt-calliope/docs/lessons/happy-birthday/activity.md
2016-11-01 17:44:37 -07:00

57 lines
2.7 KiB
Markdown

# happy birthday blocks activity
Play sounds with music blocks.
Have you ever tried to play a song on an instrument? Let's try coding the song "Happy Birthday" on the @boardname@ !
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@.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
```
* 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
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));
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
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));
basic.pause(100);
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));
basic.pause(100);
```
* click run to see if the code works as expected.
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/happy-birthday/challenges)!
### ~