lessons to projects
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
# banana keyboard blocks lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Music
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/banana-keyboard/activity)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips). The connect fruit using pins P1 and GND.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to setup the BBC micro:bit with earphones to play music
|
||||
* learn how to setup the BBC micro:bit with fruit be the musical instrument
|
||||
|
@ -1,100 +0,0 @@
|
||||
# banana keyboard activity
|
||||
|
||||
build a banana keyboard
|
||||
|
||||
# micro:bit banana keyboard
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack.
|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND.
|
||||
|
||||
### Step 6
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange.
|
||||
|
||||
### Step 7
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.
|
||||
|
||||
### Step 8
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
|
||||
|
||||
### Step 9
|
||||
|
||||

|
||||
|
||||
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](/lessons/banana-keyboard/challenges)!
|
||||
|
||||
### ~
|
@ -1,63 +0,0 @@
|
||||
# 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.
|
||||
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
# hack your headphones lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Hack your headphone
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/hack-your-headphones/activity)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, headphones (or speakers), as well as crocodile clips (or spring clips).
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to setup the BBC micro:bit with headphones to play music
|
||||
|
@ -1,61 +0,0 @@
|
||||
# hack your headphones activity
|
||||
|
||||
Hack your headphones
|
||||
|
||||
# micro:bit music
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
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)!
|
||||
|
||||
### ~
|
@ -1,62 +0,0 @@
|
||||
# rock paper scissors lesson
|
||||
|
||||
A game against the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Local Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/rock-paper-scissors/activity)
|
||||
* [challenges](/lessons/rock-paper-scissors/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a **local variable**, `var t :=time` where you can store data, so that you can use it in your code. We will be learning how to create a classic rock paper scissors game using global variables, input on shake, local variables, math random as well as simple commands such as create image, show image, show string, and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.onGesture(Gesture.Shake, () => {})
|
||||
Math.random(3)
|
||||
let x = 0
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a condition so the micro:bit will run code when it is shaken
|
||||
* learn how to create a local variable for a place where you can store data
|
||||
* learn how to create an image to show on the micro:bit's LED screen
|
||||
* learn how to show an image on the micro:bit's LED screen
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
@ -1,121 +0,0 @@
|
||||
# rock paper scissors activity
|
||||
|
||||
A classic game against the micro:bit.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
|
||||
|
||||
Welcome! This tutorial will help you create a game of rock paper scissors with the micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
We want the micro:bit to choose rock, paper, or scissors when it is shaken. Let's begin by creating an on shake condition so the micro:bit will run code when it is shaken.
|
||||
|
||||
|
||||
```blocks
|
||||
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Next, create a variable and store pick random number from 0 to 2. On shake, a number will be randomly picked from 0-2. We will randomly display an image based on the random number returned.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 2. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
```
|
||||
|
||||
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 1. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is not equal to 2 and not equal to 1. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
. . . # #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
. . . # #
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/rock-paper-scissors/challenges)!
|
||||
|
||||
### ~
|
||||
|
@ -1,133 +0,0 @@
|
||||
# rock paper scissors challenges
|
||||
|
||||
Coding challenges for rock paper scissors.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided activity](/lessons/rock-paper-scissors/activity) , your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(3)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
. . . # #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
. . . # #
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
When the A button is pressed, increment the score by 1. You can select Game drawer then add change score by 1.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(2)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
. . . # #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
. . . # #
|
||||
`)
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
* Click *run* to execute your code in the simulator
|
||||
|
||||
### Challenge 2
|
||||
|
||||
After incrementing the score, display the total number of wins you have.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = Math.random(2)
|
||||
if (img == 2) {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`)
|
||||
|
||||
} else if (img == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
} else {
|
||||
basic.showLeds(`
|
||||
. . . # #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
. . . # #
|
||||
`)
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1)
|
||||
basic.showString("WINS:")
|
||||
basic.showNumber(game.score())
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
* Run and compile the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You have successfully tracked and displayed the number of wins on the micro:bit! However, what about losses? Use the Game drawer to change score by -1 when button `B` is pressed.
|
||||
|
||||
* Run and compile the code to see if it works as expected.
|
@ -1,74 +0,0 @@
|
||||
# rock paper scissors quiz
|
||||
|
||||
shift an image horizontally across the display with offset.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [rock paper scissors tutorial](/lessons/rock-paper-scissors/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `offset` does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw which LEDs are ON after running this code and the random number returned is 0
|
||||
|
||||
```blocks
|
||||
let img = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset = Math.random(3) * 5
|
||||
img.showImage(offset)
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code with an offset of 5. This would occur if the random number returned is 1.
|
||||
|
||||
```blocks
|
||||
let img_ = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset_ = Math.random(3) * 5
|
||||
img.showImage(offset)
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code with an offset of 10. This would occur if the random number returned is 2.
|
||||
|
||||
```blocks
|
||||
let img_1 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset_1 = Math.random(3) * 5
|
||||
img.showImage(offset)
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
@ -1,24 +0,0 @@
|
||||
# telegraph lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Telegraph
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/telegraph/activity)
|
||||
* [challenges](/lessons/telegraph/challenges)
|
||||
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to convert your BBC micro:bit into a telegraph using a second BBC micro:bit as well as pin P1, P2, 3V, GND,
|
||||
and crocodile clips (or spring clips). The connect BBC micro:bit uses pins P1, P2, 3V, GND.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to setup the BBC micro:bit with crocodile clips
|
||||
* learn how to telegraph to another BBC micro:bit
|
||||
|
@ -1,75 +0,0 @@
|
||||
# telegraph activity
|
||||
|
||||
Build a telgraph.
|
||||
|
||||
# micro:bit telegraph
|
||||
|
||||

|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
|
||||
|
||||
### Step 2
|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit.
|
||||
|
||||
### Step 3
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit.
|
||||
|
||||
### Step 4
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit.
|
||||
|
||||
### Step 5
|
||||
|
||||

|
||||
|
||||
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit.
|
||||
|
||||
### Step 6
|
||||
|
||||

|
||||
|
||||
Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit.
|
||||
|
||||
### Step 7
|
||||
|
||||

|
||||
|
||||
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit.
|
||||
|
||||
### Step 8
|
||||
|
||||

|
||||
|
||||
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit
|
||||
|
||||
### Step 9
|
||||
|
||||

|
||||
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/telegraph/challenges)!
|
||||
|
||||
### ~
|
@ -1,114 +0,0 @@
|
||||
# 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:
|
||||
|
||||

|
||||
|
||||
### 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!
|
Reference in New Issue
Block a user