Migrate docs from the other repo
This commit is contained in:
51
docs/lessons/love-meter/activity.md
Normal file
51
docs/lessons/love-meter/activity.md
Normal file
@ -0,0 +1,51 @@
|
||||
# love meter blocks activity
|
||||
|
||||
Create a love meter with the micro:bit
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/love-meter-0
|
||||
|
||||
Welcome! This activity will help you create a love meter with the micro:bit. Let's get started!
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
|
||||
|
||||
### ~
|
||||
|
||||
Begin by registering an event with `on pin pressed` *P0* to know when someone is holding pin *P0* and pin *Gnd*.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
We are going to create a meter that displays a random number from *0* to *10*. We use *10* as `random number up to` returns a number between *0* and *n*.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Finally, let's show that number on the micro:bit. You are registering an event handler that will execute on the BBC micro:bit whenever the user holds the GND pin with one hand, and presses pin 0 with the other hand, thus completing a circuit
|
||||
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/love-meter/challenges)
|
||||
|
||||
### ~
|
||||
|
71
docs/lessons/love-meter/challenges.md
Normal file
71
docs/lessons/love-meter/challenges.md
Normal file
@ -0,0 +1,71 @@
|
||||
# love meter blocks challenges
|
||||
|
||||
Create a love meter with the micro:bit
|
||||
|
||||
## Before we get started
|
||||
|
||||
You should work on these challenges after the following the [love meter activity](/microbit/lessons/love-meter/activity)
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Add a pause of 3000 milliseconds (3 seconds) after showing the number so that the number won't immediately disappear in the next challenge.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
basic.pause(3000)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
If the rating **x** is between *0* and *3* (strictly less than *4*), display the text "HORRIBLE!".
|
||||
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
basic.pause(3000)
|
||||
if (x < 4) {
|
||||
basic.showString("HORRIBLE")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/love-meter-3
|
||||
|
||||
**If** the rating is between 4 and 7, display the text "MEDIOCRE!" **else** display the text "MATCHED!"
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
basic.pause(3000)
|
||||
if (x < 4) {
|
||||
basic.showString("HORRIBLE")
|
||||
} else if (x < 8) {
|
||||
basic.showString("MEDIOCRE")
|
||||
} else {
|
||||
basic.showString("MATCHED")
|
||||
}
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Use `show LEDs` to display images instead of text for each case.
|
||||
|
40
docs/lessons/love-meter/quiz-answers.md
Normal file
40
docs/lessons/love-meter/quiz-answers.md
Normal file
@ -0,0 +1,40 @@
|
||||
# love meter blocks quiz answers
|
||||
|
||||
The answers to the love meter quiz.
|
||||
|
||||
This is the answer key for the [love meter quiz](/microbit/lessons/love-meter/quiz).
|
||||
|
||||
## 1. What does `on pin pressed(P0)` do?
|
||||
|
||||
<br/>
|
||||
|
||||
It's a method that runs code when the user holds the GND pin with a finger of one hand and presses pin P0, completing a circuit.
|
||||
|
||||
## 2. Write the code.
|
||||
|
||||
Create a condition for `on pin pressed (P0)`.
|
||||
|
||||

|
||||
|
||||
## 3. What does this line of code doing?
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
It stores random number between 0 and 9 then stores that number in a variable.
|
||||
|
||||
## 4. Why do you have to add 1 to variable x?
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
You have to add 1 if you want to generate a random number between 1 and 10 .
|
||||
|
||||
## 5. Why do you have to hold ground (GND) to make this work on the micro:bit?
|
||||
|
||||
<br/>
|
||||
|
||||
You have told GND to complete the circuit.
|
||||
|
36
docs/lessons/love-meter/quiz.md
Normal file
36
docs/lessons/love-meter/quiz.md
Normal file
@ -0,0 +1,36 @@
|
||||
# love meter blocks quiz
|
||||
|
||||
Learn how to make a love meter that you can try with someone.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [love meter activity](/microbit/lessons/love-meter/activity).
|
||||
|
||||
Answer the questions below while completing the activity. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `on pin pressed` does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Create a condition for on pin pressed (P0).
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Describe what this line of code does?
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Describe what adding 1 to variable x does?
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using `on pin pressed(P0)` on the micro:bit
|
||||
|
||||
<br/>
|
||||
|
Reference in New Issue
Block a user