57 lines
2.7 KiB
Markdown
Raw Normal View History

2016-03-25 16:47:20 -07:00
# happy birthday blocks activity
2016-09-23 22:27:57 -07:00
Play sounds with music blocks.
2016-03-25 16:47:20 -07:00
2016-11-01 17:44:37 -07: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-25 16:47:20 -07:00
2016-11-01 17:44:37 -07: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-25 16:47:20 -07:00
```blocks
2016-09-23 22:27:57 -07:00
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quarter));
2016-03-25 16:47:20 -07: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-23 22:27:57 -07: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-25 16:47:20 -07: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-23 22:27:57 -07: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-25 16:47:20 -07:00
basic.pause(100);
2016-09-23 22:27:57 -07: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-25 16:47:20 -07:00
basic.pause(100);
```
* click run to see if the code works as expected.
## ~avatar boothing
2016-03-25 16:47:20 -07:00
2016-04-13 08:27:45 -07:00
Excellent, you're ready to continue with the [challenges](/lessons/happy-birthday/challenges)!
2016-03-25 16:47:20 -07:00
## ~
2016-03-25 16:47:20 -07:00