lessons to projects

This commit is contained in:
Tom Ball
2016-06-14 11:12:13 -04:00
parent 4657263abb
commit d94c7e0157
18 changed files with 13 additions and 462 deletions

View File

@ -0,0 +1,63 @@
# banana keyboard blocks challenges
control images with variables.
## Before we get started
Control images with variables.
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
We will register an event handler on the fruit that will execute when two things occur: first, the alligator clip attaches to GND and the other side of the alligator clip is inserted into a banana. Let's start by adding a variable where you can store data. Then rename the variable to "sound". Then set the value of the variable to the note block `A` from the Music drawer. Modify your code so that your code looks like this.
```blocks
let sound = music.noteFrequency(Note.A);
```
We want to play music on pin pressed in order to register an event handler that will execute whenever when you run a script and click pin 1 on the simulator. We must start by opening the Input drawer and adding `on pin pressed` P1. Modify your code so that your code looks like this.
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
})
```
We want to code the notes that will be played `on pin pressed`. We click on the Input drawer then insert a `for loop` that will increment by *i*. Click on the Variables drawer. Add `set item` block. Rename the variable block to "sound." Then add a Maths block to increase the variable sound from the note frequency of block `A` to `A` plus 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 < 4; i++) {
sound = sound + 25
}
})
```
* click *run* to see if the code works as expected.
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. You will need to include a second banana to a alligator (spring) clip in the same procedure as the first activity.
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 4; i++) {
sound = sound + 25
}
})
input.onPinPressed(TouchPin.P2, () => {
for (let i = 0; i < 4; i++) {
sound = sound - 25
}
})
```
* click *run* to see if the code works as expected.

View File

@ -0,0 +1,100 @@
# banana keyboard activity
build a banana keyboard
# micro:bit banana keyboard
![](/static/mb/lessons/banana-keyboard-0.png)
In this project, you will build your own music player micro:bit banana keyboard from household fruit. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Bananas
* Orange
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/banana-keyboard-2.png)
![](/static/mb/lessons/banana-keyboard-3.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/lessons/banana-keyboard-4.png)
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/banana-keyboard-6.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack.
### Step 5
![](/static/mb/lessons/banana-keyboard-7.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND.
### Step 6
![](/static/mb/lessons/banana-keyboard-8.png)
![](/static/mb/lessons/banana-keyboard-9.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange.
### Step 7
![](/static/mb/lessons/banana-keyboard-10.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.
### Step 8
![](/static/mb/lessons/banana-keyboard-11.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
### Step 9
![](/static/mb/lessons/banana-keyboard-12.png)
Your banana keyboard is ready!
### Step 10
Connect your micro:bit to your computer using your USB cable and run this script:
```blocks
let sound = music.noteFrequency(Note.C);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25;
music.playTone(sound, music.beat(BeatFraction.Sixteenth));
}
});
```
Tap your banana instrument to play sound against... the fruit!
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/banana-keyboard-challenges)!
### ~

View File

@ -1,4 +1,4 @@
# compass activity
# compass
![](/static/mb/projects/a5-compass.png)

View File

@ -1,3 +1,5 @@
# flashing heart
![](/static/mb/projects/a1-display.png)
Use the LEDs to display a flashing heart.

View File

@ -0,0 +1,61 @@
# hack your headphones
Hack your headphones
# micro:bit music
![](/static/mb/lessons/hack-your-headphones-0.png)
In this project, you will build your own music player micro:bit from headphones. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Headphones
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/banana-keyboard-2.png)
![](/static/mb/lessons/banana-keyboard-3.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/lessons/banana-keyboard-4.png)
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack. The base of your headphone jack is considered the ground so it is connected to the GND of the micro:bit.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/hack-your-headphones-1.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto the tip of the headphone jack. The tip of your headphone jack feeds into the right speaker on the headphone. You connect from the micro:bit pin 0 to the tip of the right side of your headphone. Use the tip of the headphone jack to play sounds.
### Step 5
![](/static/mb/lessons/hack-your-headphones-0.png)
You hacked your headphones!
### Step 6
Connect your micro:bit to your computer using your USB cable and program [light beatbox](/lessons/light-beatbox/activity) music on it. Press the reset button to restart your music player!
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/light-beatbox/activity)!
### ~

View File

@ -1,3 +1,5 @@
# love meter
![](/static/mb/projects/a3-pins.png)
Use pins P0, P1 and P2 to change the display by creating a circuit with your body.

View File

@ -1,3 +1,5 @@
# smiley buttons
![](/static/mb/projects/a2-buttons.png)
Use buttons to show a smiley or frowny face.

View File

@ -0,0 +1,114 @@
# telegraph activity
Build a telgraph.
# micro:bit telegraph
Have you ever tried to communicate through a telegraph? Let's try coding a "Telegraph" on two BBC micro:bits !
Complete the following [guided tutorial](/lessons/telegraph/activity), your hack should look like this:
![](/static/mb/lessons/telegraph-0.png)
### Step 1
We now need to digitally write to the specified pin (P0) as digital. Let's start by adding the code in the pin drawer that includes 'digital write (0,1) to pin P0'.. Then insert 1 for digital write.
```blocks
pins.digitalWritePin(DigitalPin.P0, 1)
```
### Step 2
We want to add a block to turn on an LED in the middle area of the LED display using plot x, y. So insert the appropriate LED plot x, y.
```blocks
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
```
### Step 3
We want to insert a condition that tells us when to turn on the LED. So insert the if block under logic drawer. Then add a condition that occurs if we do not turn on a LED with plot x, y. We also should plot an LED on the display if button A is pressed. Your code should appear as follows:
```blocks
if (input.buttonIsPressed(Button.A)) {
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
} else {
}
```
### Step 4
We want to write code if button A is NOT pressed. It is important to say that digital write is not on. We also want to turn off all LED lights on the LED screen
```blocks
if (input.buttonIsPressed(Button.A)) {
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
} else {
pins.digitalWritePin(DigitalPin.P0, 0)
basic.clearScreen()
}
```
### Step 5
Let's add a forever loop so this code runs in the background forever. Modify your code so that your code looks like this. Run the code and press Button A.
```blocks
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
pins.digitalWritePin(DigitalPin.P0, 1)
led.plot(2, 2)
} else {
pins.digitalWritePin(DigitalPin.P0, 0)
basic.clearScreen()
}
})
```
### Step 6
We now need to digitally read to the specified pin (P1) as digital. Let's start by going to the pin drawer and adding digital read pin (0,1) and changing the pin to P1. Now we need to create a condition for digital read pin (0,1). So we go to the logic drawer and select the comparison operator. Then we want to set the comparison operator to 1 to turn on digital read on pin 1. We want to insert a condition that tells us if button A is pressed and we should turn on digital read on pin 1. So insert the if block under logic drawer. Then add a condition that occurs if digital read on P1 is on. Then we want to plot x, y at the x, y coordinates of 2,2. we also want to say that if digital read pin P1 is not on, we want to turn off all LED lights on the screen. Your code should appear as follows:
```blocks
if (pins.digitalReadPin(DigitalPin.P1) == 1) {
led.plot(2, 2);
}
else {
basic.clearScreen();
}
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
pins.digitalWritePin(DigitalPin.P0, 1);
led.plot(2, 2);
}
else {
pins.digitalWritePin(DigitalPin.P0, 0);
basic.clearScreen();
}
});
```
Your telegraph is ready!
### Step 7
* Connect the first micro:bit to your computer using your USB cable and run the [telegraph](/nnudbr) script on it.
* Connect the second micro:bit to your computer using your USB cable and run the [telegraph](/nnudbr) script on it.
* The first person and second person take turns pressing button A to play the telegraph game!

View File

@ -0,0 +1,75 @@
# telegraph activity
Build a telgraph.
# micro:bit telegraph
![](/static/mb/lessons/telegraph-0.png)
In this project, you will build your telegraph between micro:bits. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/ornament-chain-2.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit.
### Step 3
![](/static/mb/lessons/ornament-chain-3.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit.
### Step 4
![](/static/mb/lessons/ornament-chain-4.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit.
### Step 5
![](/static/mb/lessons/ornament-chain-5.png)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit.
### Step 6
![](/static/mb/lessons/ornament-chain-6.png)
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit.
### Step 7
![](/static/mb/lessons/ornament-chain-7.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit.
### Step 8
![](/static/mb/lessons/ornament-chain-8.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit
### Step 9
![](/static/mb/lessons/telegraph-0.png)
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/projects/telegraph-challenges)!
### ~

View File

@ -1,6 +1,6 @@
![](/static/mb/projects/a10-watch.png)
# micro:bit watch
# the watch
![](/static/mb/lessons/the-watch-0.png)