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
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 micro:bit !
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 micro:bit.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
```
* 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.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
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.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
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
### ~