pxt-calliope/olddocs/lessons/classic-beatbox/challenges.md

49 lines
1.4 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# beatbox challenges
Create sounds with variables.
## Before we get started
2016-04-16 00:02:26 +02:00
Complete the [beatbox](/lessons/classic-beatbox/activity) activity and your code will look like this:
2016-03-26 00:47:20 +01:00
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 4; i++) {
sound = sound + 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
```
2016-05-06 18:28:26 +02:00
### Challenge 1
2016-03-26 00:47:20 +01:00
Let's include a second sound `on pin pressed` *P2*. To do this, you need to add the same blocks as the banana keyboard activity. However, you must change alter `on pin pressed` from P1 to P2. Additionally, you must *decrease* the frequency of the variable "sound" by 25. Modify your code so that your code looks like this
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
input.onPinPressed(TouchPin.P2, () => {
for (let i = 0; i < 5; i++) {
sound = sound - 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
```
* click *run* to see if the code works as expected.
2016-05-06 18:28:26 +02:00
### Challenge 2
2016-03-26 00:47:20 +01:00
Finally, we want images to be displayed with sounds `on pin pressed`. Add `show LEDs` blocks under `on pin pressed` P1 and P2.