f4eca66648
will move select lessons back to "educators" section
57 lines
2.7 KiB
Markdown
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 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
|
|
|
|
Excellent, you're ready to continue with the [challenges](/lessons/happy-birthday/challenges)!
|
|
|
|
### ~
|
|
|