move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
32
olddocs/lessons/answering-machine.md
Normal file
32
olddocs/lessons/answering-machine.md
Normal file
@ -0,0 +1,32 @@
|
||||
# answering machine blocks lesson
|
||||
|
||||
Create an answering machine on the BBC micro:bit
|
||||
|
||||
## Topic
|
||||
|
||||
Show String
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/answering-machine/activity)
|
||||
* [quiz](/lessons/answering-machine/quiz)
|
||||
* [quiz answers](/lessons/answering-machine/quiz-answers)
|
||||
* [challenges](/lessons/answering-machine/challenges)
|
||||
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a message with a **string**, `show string` to write your message. We will be learning how to create a message using simple commands, such as show string and on button pressed.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.showString('Hi!')
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to show a string on the LED screen one character at a time
|
||||
* learn how to use to register an event handler that will execute whenever an input button is pressed
|
||||
|
23
olddocs/lessons/answering-machine/activity.md
Normal file
23
olddocs/lessons/answering-machine/activity.md
Normal file
@ -0,0 +1,23 @@
|
||||
# answering machine blocks activity
|
||||
|
||||
Learn to create an answering machine on the micro:bit
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
|
||||
Let's learn how to create an answering machine!
|
||||
|
||||
### ~
|
||||
|
||||
We will use `show string` to show text on the LED screen. *String* is a common name for *text* in programming languages. The function `show string` scrolls the text column by column at a *150* milliseconds interval.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK ME A QUESTION")
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/answering-machine/challenges)!
|
||||
|
||||
### ~
|
||||
|
45
olddocs/lessons/answering-machine/challenges.md
Normal file
45
olddocs/lessons/answering-machine/challenges.md
Normal file
@ -0,0 +1,45 @@
|
||||
# answering machine blocks challenges
|
||||
|
||||
Coding challenges for the answering machine tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [answering machine](/lessons/answering-machine/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK ME A QUESTION")
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now we need to reply after someone asks micro:bit a yes or no question. We want to respond `YES` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YES`.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK ME A QUESTION")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Yes")
|
||||
})
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
What if micro:bit's answer to the question is no? Let's have `NO` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the string `NO`.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK ME A QUESTION")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("Yes")
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("NO")
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.
|
38
olddocs/lessons/answering-machine/quiz-answers.md
Normal file
38
olddocs/lessons/answering-machine/quiz-answers.md
Normal file
@ -0,0 +1,38 @@
|
||||
# answering machine blocks quiz answers
|
||||
|
||||
Create an answering machine on the micro:bit.
|
||||
|
||||
This is the answer key for the [answering machine quiz](/lessons/answering-machine/quiz).
|
||||
|
||||
## 1. Define what `show string` does?
|
||||
|
||||
Answers may vary. This is a function that will show a string on the LED screen one character at a time (scrolling from left to right).
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
basic.showString("Y")
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("Hi")
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
## 4. If the rectangle below represents the micro:bit, write the code to display the letter "Z".
|
||||
|
||||

|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("Z")
|
||||
```
|
||||
|
||||
|
46
olddocs/lessons/answering-machine/quiz.md
Normal file
46
olddocs/lessons/answering-machine/quiz.md
Normal file
@ -0,0 +1,46 @@
|
||||
# answering machine blocks quiz
|
||||
|
||||
Create an answering machine on the micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [answering machine activity](/lessons/answering-machine/activity).
|
||||
|
||||
Answer the questions while completing the activity. Pay attention to the dialogues!
|
||||
|
||||
## 1. Define what `show string` does?
|
||||
|
||||
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("Y")
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("Hi")
|
||||
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
## 4. If the rectangle below represents the micro:bit, write the code to display the letter "Z".
|
||||
|
||||
```blocks
|
||||
basic.showString("Z")
|
||||
|
||||
```
|
||||
|
||||
|
36
olddocs/lessons/beautiful-image.md
Normal file
36
olddocs/lessons/beautiful-image.md
Normal file
@ -0,0 +1,36 @@
|
||||
# beautiful image lesson
|
||||
|
||||
Display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Show LEDs
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/beautiful-image/activity)
|
||||
* [challenges](/lessons/beautiful-image/challenges)
|
||||
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to **show LEDs**, to show an image on the BBC micro:bit's LED screen. We will be learning how to Show LEDs using simple commands such as Show LEDs and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
basic.pause(100)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to display an image on the micro:bit's LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
28
olddocs/lessons/beautiful-image/activity.md
Normal file
28
olddocs/lessons/beautiful-image/activity.md
Normal file
@ -0,0 +1,28 @@
|
||||
# beautiful image blocks activity
|
||||
|
||||
Generate and show a beautiful image.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Let's learn how to show an image on the LED screen.
|
||||
|
||||
### ~
|
||||
|
||||
We will use *show LEDs* to draw an image on the LED screen. This function immediately writes on the screen.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # . # #
|
||||
# . # . #
|
||||
# # . # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/beautiful-image/challenges)!
|
||||
|
||||
### ~
|
||||
|
45
olddocs/lessons/beautiful-image/challenges.md
Normal file
45
olddocs/lessons/beautiful-image/challenges.md
Normal file
@ -0,0 +1,45 @@
|
||||
# beautiful image blocks challenges
|
||||
|
||||
Coding challenges for the beautiful image tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [beautiful image](/lessons/beautiful-image/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # . # #
|
||||
# . # . #
|
||||
# # . # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now show an new image that will display on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # . # #
|
||||
# . # . #
|
||||
# # . # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.showLeds(`
|
||||
# . # . #
|
||||
. # # # .
|
||||
. . # . .
|
||||
. # # # .
|
||||
# . # . #
|
||||
`)
|
||||
```
|
||||
|
||||
* Does your code work as expected?
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Nice job! Why don't we create a third image that will show after the other two?
|
||||
|
48
olddocs/lessons/beautiful-image/tutorial.md
Normal file
48
olddocs/lessons/beautiful-image/tutorial.md
Normal file
@ -0,0 +1,48 @@
|
||||
# beautiful image blocks challenges
|
||||
|
||||
Beautiful Image tutorial.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/beautiful-image-0
|
||||
|
||||
Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that…
|
||||
|
||||
* display images on the screen with show LEDs
|
||||
|
||||
|
||||
```shuffle
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # . # #
|
||||
# . # . #
|
||||
# # . # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.showLeds(`
|
||||
# . # . #
|
||||
. # # # .
|
||||
. . # . .
|
||||
. # # # .
|
||||
# . # . #
|
||||
`)
|
||||
basic.pause(100)
|
||||
```
|
||||
|
||||
Hints and tips
|
||||
|
||||
Cut out these documentation cards to help you!
|
||||
|
||||
```cards
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
basic.pause(100)
|
||||
|
||||
```
|
36
olddocs/lessons/blink.md
Normal file
36
olddocs/lessons/blink.md
Normal file
@ -0,0 +1,36 @@
|
||||
# blink blocks lesson
|
||||
|
||||
Learn how to create a blinking LED.
|
||||
|
||||
## Topic
|
||||
|
||||
Plot
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/lessons/blink/activity)
|
||||
* [quiz](/lessons/blink/quiz)
|
||||
* [quiz answers](/lessons/blink/quiz-answers)
|
||||
* [challenges](/lessons/blink/challenges)
|
||||
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, unplot and pause.
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
led.plot(0, 0)
|
||||
led.unplot(0, 0)
|
||||
basic.pause(100)
|
||||
basic.forever(() => {})
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to turn on LED lights on the LED screen
|
||||
* learn how to turn off LED lights on the LED screen
|
||||
* learn how to pause program execution for the specified number of milliseconds
|
||||
|
61
olddocs/lessons/blink/activity.md
Normal file
61
olddocs/lessons/blink/activity.md
Normal file
@ -0,0 +1,61 @@
|
||||
# blink blocks activity
|
||||
|
||||
Turn an LED on and off with forever
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
```sim
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
Let's build a blinking light!
|
||||
|
||||
### ~
|
||||
|
||||
Have you ever tried to blink a flashlight at night? The concept is fairly simply: turn on the light, wait for a little, turn off the light, wait again, and repeat. That's exactly what we need to code to get a blinking LED.
|
||||
|
||||
Let's start by adding a line of code that turns on the LED at position 2, 2.
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||
Run your script to make sure it's correct. Then, let's add code to `pause` 500 milliseconds and turn off the LED.
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2,2)
|
||||
```
|
||||
|
||||
We've got the LED blinking once. Let's add another pause and turn on the LED again.
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||
The current code works but it only blinks once! We are going to use a `forever` loop and move the code inside it to repeat it forever. We've dropped the second `plot` line since we don't need it in the loop.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/blink/challenges)!
|
||||
|
||||
### ~
|
||||
|
79
olddocs/lessons/blink/challenges.md
Normal file
79
olddocs/lessons/blink/challenges.md
Normal file
@ -0,0 +1,79 @@
|
||||
# blink blocks challenges
|
||||
|
||||
Coding challenges for the blink tutorial
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [blink](/lessons/blink/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's display a "smiley face" on the screen! We'll start by plotting the eyes.
|
||||
|
||||
Add `plot(1,1)` and `plot(3,1)` under `plot(2,2)` ; then add `unplot(1,1)`, `unplot(3,1)` and `unplot(2,2)` after `pause`. When you're ready, don't forget to run your code to try it out!
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
led.plot(1, 1)
|
||||
led.plot(3, 1)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
led.unplot(1, 1)
|
||||
led.unplot(3, 1)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's add the code to plot the mouth by using `plot` and `unplot` to the following coordinates: (1,4), (2,4) and (3,4). When you're ready, don't forget to run your code to try it out!
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
led.plot(1, 1)
|
||||
led.plot(3, 1)
|
||||
led.plot(1, 4)
|
||||
led.plot(2, 4)
|
||||
led.plot(3, 4)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
led.unplot(1, 1)
|
||||
led.unplot(3, 1)
|
||||
led.unplot(1, 4)
|
||||
led.unplot(2, 4)
|
||||
led.unplot(3, 4)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Let's keep using `plot` to convert the mouth into a smiley face.
|
||||
|
||||
```` bitmatrix
|
||||
0 0 0 0 0
|
||||
0 1 0 1 0
|
||||
0 0 1 0 0
|
||||
1 0 0 0 1
|
||||
0 1 1 1 0
|
||||
````
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Let's make it blink a bit faster. To do so, we need to reduce the amount of time used in ``pause`` to 100 milliseconds.
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Create your own image by changing the coordinates in `plot` and `unplot`!
|
||||
|
49
olddocs/lessons/blink/quiz-answers.md
Normal file
49
olddocs/lessons/blink/quiz-answers.md
Normal file
@ -0,0 +1,49 @@
|
||||
# blink blocks quiz answers
|
||||
|
||||
Learn how to create a blinking LED script.
|
||||
|
||||
This is the answer key for the [blink quiz](/lessons/blink/quiz).
|
||||
|
||||
## 1. Describe what `plot` does?
|
||||
|
||||
Answers will vary. In general, plot refers to the code that turns on a specific LED. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
By default, the position of an LED on *Blink Tutorial* is set to the centre of the screen. This code turns on the centre LED
|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
led.plot(0, 0)
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
* ``x`` - the x coordinate or horizontal position (0)
|
||||
* ``y`` - the y coordinate or vertical position (0)
|
||||
|
||||
## 4. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
led.plot(4, 4)
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using ``x``, ``y`` coordinates.
|
||||
|
||||
* ``x`` - the x coordinate or horizontal position (4)
|
||||
* ``y`` - the y coordinate or vertical position (4)
|
||||
|
45
olddocs/lessons/blink/quiz.md
Normal file
45
olddocs/lessons/blink/quiz.md
Normal file
@ -0,0 +1,45 @@
|
||||
# blink blocks quiz
|
||||
|
||||
Learn how to create a blinking LED script.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [blink activity](/lessons/blink/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `plot` does?
|
||||
|
||||
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
```blocks
|
||||
led.plot(0, 0)
|
||||
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 4. Draw which LED is ON after running this code
|
||||
|
||||
|
||||
```blocks
|
||||
led.plot(4, 4)
|
||||
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
50
olddocs/lessons/blocks-conditions.md
Normal file
50
olddocs/lessons/blocks-conditions.md
Normal file
@ -0,0 +1,50 @@
|
||||
# blocks - if statements
|
||||
|
||||
An introduction to conditions for the Block Editor.
|
||||
|
||||
## Introduction to conditions
|
||||
|
||||
In the introduction to code, we made the BBC micro:bit automatically shows the message ‘hello, world!’:
|
||||
|
||||

|
||||
|
||||
This statement, or code, will happen as soon as the BBC micro:bit is activated. This means it is unconditional. We can add a condition to make code function in certain ways:
|
||||
|
||||
* A calculator waits for the user in input numbers and a function, before outputting a result
|
||||
* A game waits for the user to press a button at the right time before outputting their score
|
||||
* A quiz waits for the user to choose the correct option, and if they are wrong the quiz will tell the user
|
||||
|
||||
In programming we use an ‘if’ statement: if this condition is met, do something. Lets add an if statement to the code we had before; the BBC Micro:bit will wait for the user to press a button before showing the image.
|
||||
|
||||
### Write the code
|
||||
|
||||
Click the **if** category and drag an `if/do` block. Drag the`show string` block we wrote previously into the `do` section of the block. Next click the **input** tab and drag a `button pressed` block, connect it to the open jigsaw of the `if` block. This is our criteria: `if A button is pressed`. We can change which button (button A or B) by clicking the arrow next to ‘A’ and changing the value. This means our BBC micro:bit is waiting for button A (the left button) to be pressed. Finally go to the **basic** tab and drag a `forever` block, and attach all our code inside. We add this block to ensure the BBC micro:bit is always waiting to show us this message, not just once. Your code should look like this:
|
||||
|
||||

|
||||
|
||||
Again, test the code in the simulator. Try clicking **Button A** to display the "hello, world!" message every time the `button is pressed`.
|
||||
|
||||
### More 'if' statements
|
||||
|
||||
You could now add additional conditions to your 'if statement'. Here are some ideas:
|
||||
|
||||
* Change the 'get button' to ask for button B
|
||||
* Add another 'if' statement within the current one, and make it so both buttons must be pressed to show the message
|
||||
* Create a mini quiz that asks for one button to be pressed which represents an answer
|
||||
|
||||
## Else
|
||||
|
||||
What if the user does not press a button? What if the user presses the wrong button? We call this an else, because if the criteria of the if statement are not met then something else is done.
|
||||
|
||||
For example, we could make it so our BBC Micro:bit tells us to press the A button. Remove the `button pressed` and `show string` blocks from the `if` block and right click it and select **Delete**. Now click the **If** category and drag out an `else if` block. Plug the `button pressed` and `show string` blocks in the correct places.
|
||||
|
||||
We want the message "Press A!" to scroll across the BBC micro:bit, so right-click the `show string` block and select **Duplicate**. Drag this new block into the `else` section and replace the “hello, world!” with "Press A!". Your code should look like this:
|
||||
|
||||

|
||||
|
||||
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the BBC micro:bit to the computer then click **compile** to send the code onto the BBC micro:bit.
|
||||
|
||||
## What is a condition?
|
||||
|
||||
A condition is criteria that the user must meet for a certain function to be carried out.
|
||||
|
83
olddocs/lessons/bop-it/activity.md
Normal file
83
olddocs/lessons/bop-it/activity.md
Normal file
@ -0,0 +1,83 @@
|
||||
# bop it challenges
|
||||
|
||||
a game similar to "Simon Says" with the BBC micro:bit.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial. Your code should look like this:
|
||||
|
||||
```blocks
|
||||
newAction() // ***
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (action == 0) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
input.onLogoDown(() => {
|
||||
if (action == 1) {
|
||||
game.addScore(1) // ***
|
||||
newAction()
|
||||
}
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
if (action == 2) {
|
||||
game.addScore(1)
|
||||
newAction()
|
||||
}
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(game.score(), 150) // ***
|
||||
basic.pause(2000) // ***
|
||||
newAction() // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's add some more types of instructions for the player to follow. Let's add `PRESS PIN 0`. Change the global variable `action` to `math->random(4)` so that we can add a new **IF** statement that checks if `action=3`. If it does, display instructions to press pin 0.
|
||||
|
||||
```blocks
|
||||
/**
|
||||
* {highlight}
|
||||
*/
|
||||
export function newAction_() {
|
||||
action = Math.random(4) // ***
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150) // ***
|
||||
}
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150) // ***
|
||||
}
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150) // ***
|
||||
}
|
||||
if (action == 3) {
|
||||
basic.showString("PRESS PIN 0", 150) // ***
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showNumber(game.score(), 150) // ***
|
||||
basic.pause(2000) // ***
|
||||
newAction() // ***
|
||||
}) // ***
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
if (action == 3) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add `POINT ME NORTH` to the list of possible commands.
|
||||
|
77
olddocs/lessons/bop-it/quiz-answers.md
Normal file
77
olddocs/lessons/bop-it/quiz-answers.md
Normal file
@ -0,0 +1,77 @@
|
||||
# bop it quiz answers
|
||||
|
||||
a game where you have to keep up with the commands.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
|
||||
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
```
|
||||
|
||||
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let action = Math.random(3)
|
||||
if (action == 0) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
|
||||
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
```blocks
|
||||
let action = Math.random(3)
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
let action = Math.random(3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
38
olddocs/lessons/bop-it/quiz.md
Normal file
38
olddocs/lessons/bop-it/quiz.md
Normal file
@ -0,0 +1,38 @@
|
||||
# bop it quiz
|
||||
|
||||
a game where you have to keep up with the commands.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
### 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
|
||||
|
||||
<br/>
|
||||
|
||||
### 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
<br />
|
||||
|
||||
### 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
### 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
### 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
### 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
<br />
|
||||
|
||||
### 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2
|
||||
|
51
olddocs/lessons/catch-the-egg-game.md
Normal file
51
olddocs/lessons/catch-the-egg-game.md
Normal file
@ -0,0 +1,51 @@
|
||||
# catch the egg game lesson
|
||||
|
||||
A game to catch eggs in a basket.
|
||||
|
||||
## Topic
|
||||
|
||||
Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/catch-the-egg-game/activity)
|
||||
* [tutorial](/lessons/catch-the-egg-game/tutorial)
|
||||
* [quiz](/lessons/catch-the-egg-game/quiz)
|
||||
* [quiz answers](/lessons/catch-the-egg-game/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a catch the egg game game with **plot**, `led->plot` , **unplot**, `led->unplot`, and **acceleration** `input -> acceleration` to turn on and off LED lights on the LED screen. We will be learning how to create a catch the egg game app using global variables, forever loop, local variable, input acceleration, math min, math max, math random, math mod, if (conditionals), game library as well as simple commands, such as led plot, led unplot, and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
let x = 2;
|
||||
led.unplot(0, 0);
|
||||
basic.forever(() => {});
|
||||
x += 1;
|
||||
led.plot(0, 0);
|
||||
basic.pause(300);
|
||||
input.acceleration(Dimension.X);
|
||||
Math.min(0,0);
|
||||
Math.max(0,1);
|
||||
Math.random(5);
|
||||
game.addScore(1);
|
||||
game.score();
|
||||
game.removeLife(1);
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to turn off a LED light on the LED screen
|
||||
* learn how to turn on a LED light on the LED screen
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to learn how to get the acceleration value (g-force), in one of three specified dimensions
|
||||
* learn how to return the smaller of two numbers
|
||||
* learn how to return the larger of two numbers
|
||||
* learn how to return a random number
|
||||
* learn how to return the modulus
|
||||
* learn how to show a number of the BBC micro:bit screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
148
olddocs/lessons/catch-the-egg-game/activity.md
Normal file
148
olddocs/lessons/catch-the-egg-game/activity.md
Normal file
@ -0,0 +1,148 @@
|
||||
# catch the egg game challenges
|
||||
|
||||
## Before we get started
|
||||
|
||||
Your starting code should look like this:
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar impressed
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's use an **IF** statement to detect if the egg and the basket are lined up.
|
||||
|
||||
Now that we know when an egg is caught, we can keep track of the score! We need to use the `add score` function built into the game library to add `1` point for every egg that is caught. However, let's not forget to `remove life` if an egg falls off the display before it's caught!
|
||||
|
||||
### ~
|
||||
|
||||
```blocks
|
||||
let basketX1 = 2
|
||||
let eggX1 = 2
|
||||
let eggY1 = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX1, 4)
|
||||
led.unplot(eggX1, eggY1)
|
||||
eggY1 = eggY1 + 1
|
||||
led.plot(eggX1, eggY1)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX1, 4)
|
||||
if (eggY1 > 4) {
|
||||
eggY1 = -1
|
||||
eggX1 = Math.random(5)
|
||||
}
|
||||
if (eggY1 == 4) {
|
||||
if (basketX1 == eggX1) {
|
||||
game.addScore(1)
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
* Press the `run` button to test out your game.
|
||||
|
||||
### ~avatar avatar encourage
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Catching eggs gets easier with practice so let's make the eggs fall faster every 5 catches. We can do this by tracking how long the egg pauses in each position while falling with a global variable called **falling pause**. Let's create this variable and set it to `300` initially. Don't forget to also create a condition that will be true every 5 catches.
|
||||
|
||||
### ~
|
||||
|
||||
```blocks
|
||||
let basketX2 = 2
|
||||
let eggX2 = 2
|
||||
let eggY2 = 0
|
||||
let fallingPause = 300 // ***
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX2, 4)
|
||||
led.unplot(eggX2, eggY2)
|
||||
eggY2 = eggY2 + 1
|
||||
led.plot(eggX2, eggY2)
|
||||
basic.pause(300)
|
||||
let accX2 = input.acceleration(Dimension.X)
|
||||
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
|
||||
led.plot(basketX2, 4)
|
||||
if (eggY2 > 4) {
|
||||
eggY2 = -1
|
||||
eggX2 = Math.random(5)
|
||||
}
|
||||
if (eggY2 == 4) {
|
||||
if (basketX2 == eggX2) {
|
||||
game.addScore(1)
|
||||
if (game.score() %5 == 0) {
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar surprised
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**.
|
||||
|
||||
```blocks
|
||||
let basketX3 = 2
|
||||
let eggX3 = 2
|
||||
let eggY3 = 0
|
||||
let fallingPause1 = 300
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX3, 4)
|
||||
led.unplot(eggX3, eggY3)
|
||||
eggY3 = eggY3 + 1
|
||||
led.plot(eggX3, eggY3)
|
||||
basic.pause(300)
|
||||
let accX3 = input.acceleration(Dimension.X)
|
||||
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
|
||||
led.plot(basketX3, 4)
|
||||
if (eggY3 > 4) {
|
||||
eggY3 = -1
|
||||
eggX3 = Math.random(5)
|
||||
}
|
||||
if (eggY3 == 4) {
|
||||
if (basketX3 == eggX3) {
|
||||
game.addScore(1)
|
||||
if (game.score()% 5 == 0) {
|
||||
fallingPause1 = fallingPause1 - 25 // ***
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(fallingPause1)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Fantastic! Your game is now ready to show off.
|
||||
|
||||
* Press the `run` button to see your finished game!
|
58
olddocs/lessons/catch-the-egg-game/quiz-answers.md
Normal file
58
olddocs/lessons/catch-the-egg-game/quiz-answers.md
Normal file
@ -0,0 +1,58 @@
|
||||
# catch the egg game quiz answers
|
||||
|
||||
Programming a game of catch the egg using the accelerometer
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg activity](/lessons/catch-the-egg-game/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the global variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
'Basket' and 'egg' are stored as **Number**.
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
led.plot(eggX, eggY)
|
||||
led.plot(basketX, 4)
|
||||
```
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
```
|
||||
|
||||
## 4. . Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
```
|
||||
|
30
olddocs/lessons/catch-the-egg-game/quiz.md
Normal file
30
olddocs/lessons/catch-the-egg-game/quiz.md
Normal file
@ -0,0 +1,30 @@
|
||||
# catch the egg game quiz
|
||||
|
||||
Programming a game of catch the egg using the accelerometer.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg challenges](/lessons/catch-the-egg-game/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
29
olddocs/lessons/catch-the-egg-game/tutorial.md
Normal file
29
olddocs/lessons/catch-the-egg-game/tutorial.md
Normal file
@ -0,0 +1,29 @@
|
||||
# catch the egg game tutorial
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* an egg LED falls from the top of the screen, row by row.
|
||||
* a basket LED is on the bottom row and can be moved by using the accelerometer `X` data.
|
||||
* if the egg LED reaches the last row, reset the egg position to the first row.
|
||||
|
||||
```shuffle
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration(Dimension.X)
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
88
olddocs/lessons/challenges.md
Normal file
88
olddocs/lessons/challenges.md
Normal file
@ -0,0 +1,88 @@
|
||||
# blocks - challenges
|
||||
|
||||
Extra stuff for the Block Editor - an introduction to GPIO
|
||||
|
||||
## Before we get started
|
||||
|
||||
This section details challenges for the BBC micro:bit. Ensure you have completed all other sections of the Microsoft Block Editor tutorials before attempting these challenges!
|
||||
|
||||
## Quiz Challenge [1]
|
||||
|
||||
Using if statements, try to add more statements to create a simple quiz. The user will be told if the question is right or not, and will have two options (button A and button B).
|
||||
|
||||
Here is some sample code for a simple quiz:
|
||||
|
||||

|
||||
|
||||
## Timer Challenge [2]
|
||||
|
||||
Create a timer that runs out after a certain amount of time (using the *count* loop). For an extra challenge, let the user input the amount of seconds they want the timer to run for using variables and the buttons as input. The solution is below.
|
||||
|
||||

|
||||
|
||||
## Graphics Challenges [3]
|
||||
|
||||
Using the knowledge you have learnt from the [rendering graphics](/lessons/graphics) section, try creating an algorithm to draw these shapes. Before you write the code try to figure out how the BBC micro:bit will be thinking to plot these points. For example, with our diagonal line – “count up from 0 to 4 by 1, and plot points x=i and y=i”.
|
||||
|
||||
* Another diagonal line
|
||||
* A square going around the board
|
||||
* A filled square
|
||||
* A square which unplots itself after
|
||||
* A filled square which then unplots itself
|
||||
|
||||
The solutions are below.
|
||||
|
||||
### Square [3.1]
|
||||
|
||||

|
||||
|
||||
### Filled square [3.2]
|
||||
|
||||

|
||||
|
||||
### Vanishing square [3.3]
|
||||
|
||||
Use the same code and algorithm for the square solution, only use the ‘unplot’ block to make this LED turn off again. You could also reverse the algorithm.
|
||||
|
||||
### Vanishing filled square [3.4]
|
||||
|
||||
Use the same code and algorithm for the filled square solution, only use the `unplot` block to make this LED turn off again. You could also reverse the algorithm.
|
||||
|
||||
## Animation Challenge [4]
|
||||
|
||||
Use your new knowledge of animations and algorithms to program your BBC micro:bit to act human: for example, you could make your BBC micro:bit smile and wink. Remember you can display images with the `show image` and `create image` blocks. Sample code is below.
|
||||
|
||||

|
||||
|
||||
## Electronic Dice Challenge [5]
|
||||
|
||||
Using the code in the Random Numbers tutorial in Section 6, or your own algorithm, create an electronic dice that displays the values appropriate for a dice (so 1 shows a single LED on in the center, two shows two LEDs on at each corner, etc.). You may want to declare image variables to do this, then check what it is equal to using an ‘if’ statement. Sample code is below.
|
||||
|
||||

|
||||
|
||||
## Calculator Challenge [6]
|
||||
|
||||
Using your knowledge of loops, counters and math, create a calculator.
|
||||
|
||||
The calculator should:
|
||||
|
||||
* Count the amount of times the user presses the left button before pressing the right button (this is the first value, or valueOne)
|
||||
* Count the amount of times the user presses the left button before the right button again (this is the second value, or valueTwo)
|
||||
* Scroll through operations (+,-, x and divide) until the user presses the right button to make a choice
|
||||
* Perform the calculation
|
||||
* Show the entire calculation, for example: 5 + 10 = 15
|
||||
|
||||
Sample code is below.
|
||||
|
||||

|
||||
|
||||
## Smart watch Challenge [8]
|
||||
|
||||
Create a smart watch using the BBC micro:bit. Create a menu where the user presses one button to cycle through options and another button to choose this option. Add applications to this smart watch:
|
||||
|
||||
* Calculators
|
||||
* Games
|
||||
* Random number generators
|
||||
|
||||
And any other applications you can think of.
|
||||
|
37
olddocs/lessons/charting.md
Normal file
37
olddocs/lessons/charting.md
Normal file
@ -0,0 +1,37 @@
|
||||
# charting lesson
|
||||
|
||||
Create a charting app for simulating and measuring the acceleration applied to the micro:bit
|
||||
|
||||
## Topic
|
||||
|
||||
Acceleration
|
||||
|
||||
## Quick Links
|
||||
* [activity](/lessons/charting/activity)
|
||||
* [challenge](/lessons/charting/challenge)
|
||||
* [quiz](/lessons/charting/quiz)
|
||||
* [answers](/lessons/charting/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn the functions of **on data received**, **send number** and **receive number** and chart `plot bar graph` for `acceleration` in the "x" dimension.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.acceleration(Dimension.X)
|
||||
led.plotBarGraph(0, 1023)
|
||||
basic.showNumber(0)
|
||||
radio.onDataReceived(() => {})
|
||||
radio.sendNumber(0)
|
||||
radio.receiveNumber()
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to get the acceleration value (g-force), in one of three specified dimensions
|
||||
* learn how to display a vertical bar graph based on the value and high value.
|
||||
* learn how to register code to run when a packet is received over radio
|
||||
* learn how to broadcast a number data packet to other micro:bits connected via radio
|
||||
* learn how to read the next radio packet as a number data packet
|
68
olddocs/lessons/charting/activity.md
Normal file
68
olddocs/lessons/charting/activity.md
Normal file
@ -0,0 +1,68 @@
|
||||
# Activity
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will teach how to use the micro:bit to chart the acceleration in the "x" direction. Let's get started!
|
||||
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` in the "x" direction. Get the acceleration value (milli g-force), in one of three specified dimensions.
|
||||
|
||||
|
||||
```blocks
|
||||
input.acceleration(Dimension.X)
|
||||
```
|
||||
|
||||
### ~
|
||||
Use the plot bar chart to visualize the acceleration on the LED screen of the micro:bit in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
Notice that moving the micro:bit in the simulator from left to right (x direction) changes the values beneath the micro:bit in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the micro:bit from left to right, you can observe changing values beneath the micro:bit simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the micro:bit simulator in the x direction. The line underneath the micro:bit simulator reflect the acceleration in the x direction.
|
||||
|
||||
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bit is yellow. So the color of the data line reflects the color of the micro:bit
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
|
||||
Vigorously move the micro:bit in the micro:bit simulatator by moving the micro:bit image from side to side. Every time the micro:bit moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the micro:bit from side to side, the more data being saved in Excel. After you have vigarously moved the micro:bit simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel that can be graphed in Excel.
|
||||
|
||||
### ~
|
||||
|
||||
We want to chart the data collected by using a tool in Excel.
|
||||
|
||||
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the micro:bit in the X direction. Then click or tap on the data Excel file that was downloaded to your local ``Downloads`` Folder.
|
||||
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the micro:bit
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/charting/challenge)
|
||||
|
||||
### ~
|
||||
|
88
olddocs/lessons/charting/challenge.md
Normal file
88
olddocs/lessons/charting/challenge.md
Normal file
@ -0,0 +1,88 @@
|
||||
# Challenge
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! The activity will teach you how to use the acceleration of the 1st micro:bit and to visualize the acceleration on the 2nd micro:bit.
|
||||
Let's get started!
|
||||
|
||||
### ~
|
||||
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other micro:bits connected via radio.
|
||||
|
||||
```blocks
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
```
|
||||
### ~
|
||||
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X));
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
### ~
|
||||
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
|
||||
})
|
||||
```
|
||||
### ~
|
||||
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
radio.sendNumber(input.acceleration(Dimension.X))
|
||||
})
|
||||
radio.onDataReceived(() => {
|
||||
led.plotBarGraph(radio.receiveNumber(), 1023)
|
||||
})
|
||||
|
||||
```
|
||||
### ~
|
||||
Notice that moving the micro:bit the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd micro:bit. There is a single LED turned on with the 1st micro:bit. Additionally, the graphs will reflect 0 acceleation for the 1st micro:bit. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
NOTE: The colors of the charts reflect the color of the micro:bit simulator. In this instance, the micro:bits are blue and green. So the colors of the line graphs reflect the colors of the micro:bit
|
||||
|
||||
### ~
|
||||
After running this simulation several seconds by moving the micro:bit side to side in the x direction, you are ready to graph or chart the accceleration of the micro:bit. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
|
||||
|
||||

|
||||
|
||||
Use the Recommended Charts command on the Insert tab to quickly create a chart that’s just right for your data.
|
||||
|
||||
* Select the data that you want to include in your chart.
|
||||
|
||||
* Click Insert > Recommended Charts.
|
||||
|
||||

|
||||
|
||||
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
|
||||
|
||||

|
||||
|
||||
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
|
||||
|
||||

|
||||
|
||||
### ~
|
||||
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
|
||||
|
||||
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
|
||||
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!
|
||||
* Review and analyze the actual micro:bit device acceleration data on Excel
|
||||
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
|
33
olddocs/lessons/charting/quiz-answers.md
Normal file
33
olddocs/lessons/charting/quiz-answers.md
Normal file
@ -0,0 +1,33 @@
|
||||
# charting quiz answers
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/charting/acceleration)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "x" axis and display this value in a bar graph.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
led.plotBarGraph(input.acceleration(Dimension.X), 0)
|
||||
```
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
23
olddocs/lessons/charting/quiz.md
Normal file
23
olddocs/lessons/charting/quiz.md
Normal file
@ -0,0 +1,23 @@
|
||||
# charting quiz
|
||||
|
||||
Measure the acceleration on the micro:bit in the "x" direction.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. After vigarously moving the micro:bit from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
|
||||
|
||||
|
23
olddocs/lessons/classic-beatbox.md
Normal file
23
olddocs/lessons/classic-beatbox.md
Normal file
@ -0,0 +1,23 @@
|
||||
# classic beatbox
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Music
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/classic-beatbox/activity)
|
||||
* [challenges](/lessons/classic-beatbox/challenges)
|
||||
|
||||
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to make a beatbox music player using pins P1 and P2. We will be learning how to code musical notes using a local variable, for loop, on pin pressed as well as simple commands such as play and notes.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to code music on the BBC micro:bit
|
||||
|
54
olddocs/lessons/classic-beatbox/activity.md
Normal file
54
olddocs/lessons/classic-beatbox/activity.md
Normal file
@ -0,0 +1,54 @@
|
||||
# beatbox activity
|
||||
|
||||
Control images with variables.
|
||||
|
||||
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Include a play block with the variable called "sound" and insert a music note block `1/16`. 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));
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
|
||||
* click *run* to see if the code works as expected.
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/classic-beatbox/challenges)!
|
||||
|
||||
### ~
|
48
olddocs/lessons/classic-beatbox/challenges.md
Normal file
48
olddocs/lessons/classic-beatbox/challenges.md
Normal file
@ -0,0 +1,48 @@
|
||||
# beatbox challenges
|
||||
|
||||
Create sounds with variables.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [beatbox](/lessons/classic-beatbox/activity) activity and your code will look like this:
|
||||
|
||||
|
||||
```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));
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
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.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Finally, we want images to be displayed with sounds `on pin pressed`. Add `show LEDs` blocks under `on pin pressed` P1 and P2.
|
||||
|
45
olddocs/lessons/compass.md
Normal file
45
olddocs/lessons/compass.md
Normal file
@ -0,0 +1,45 @@
|
||||
# compass lesson
|
||||
|
||||
create a die on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
If (Conditionals)
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/compass/activity)
|
||||
* [challenges](/lessons/compass/challenges)
|
||||
* [quiz](/lessons/compass/quiz)
|
||||
* [quiz answers](/lessons/compass/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a compass with If statements, Forever, Variables, Assignment Operator, Comparison Operator, Show String, and Show LEDs
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.compassHeading()
|
||||
basic.forever(() => {})
|
||||
let x = 0
|
||||
if (true) {}
|
||||
basic.showString("Hello!")
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
* learn how to create a local variable as a place where you can store and retrieve data
|
||||
* learn how the assignment operator is used to declare a new local variable
|
||||
* learn how to declare a new local variable or update the value of a variable
|
||||
* learn how to return a random number
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show an image on the LED screen
|
98
olddocs/lessons/compass/activity.md
Normal file
98
olddocs/lessons/compass/activity.md
Normal file
@ -0,0 +1,98 @@
|
||||
# compass activity
|
||||
|
||||
Display the direction that the micro:bit is facing using the compass
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This guided tutorial will show you how to program a script that displays the direction the micro:bit is pointing. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Create a loop that will continuously update the reading of the compass.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Store the reading of the micro:bit in a variable called `degrees`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading()
|
||||
})
|
||||
```
|
||||
|
||||
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If `degrees` is less than 135, the micro:bit is mostly pointing East. Display `E` on the micro:bit.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If `degrees` is less than 225, the micro:bit is mostly pointing South. Display `S` on the micro:bit.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
If none of these conditions returned true, then the micro:bit must be pointing West. Display `W` on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/compass/challenges)!
|
||||
|
||||
### ~
|
||||
|
88
olddocs/lessons/compass/challenges.md
Normal file
88
olddocs/lessons/compass/challenges.md
Normal file
@ -0,0 +1,88 @@
|
||||
# compass challenges
|
||||
|
||||
Display the direction that the micro:bit is facing using the compass
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/compass/activity), your code should look like this:
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Instead of displaying `N` when the BBC micro:bit is pointing North, display a star to indicate the north star.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showLeds(`
|
||||
# . # . #
|
||||
. # # # .
|
||||
# # # # #
|
||||
. # # # .
|
||||
# . # . #`);
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Instead of displaying just `N`, `W`, `S`, or `E`, display the full word.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("NORTH");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("EAST");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("SOUTH");
|
||||
}
|
||||
else {
|
||||
basic.showString("WEST");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Display your own unique message for each direction.
|
||||
|
54
olddocs/lessons/compass/quiz-answers.md
Normal file
54
olddocs/lessons/compass/quiz-answers.md
Normal file
@ -0,0 +1,54 @@
|
||||
# compass quiz answers
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass tutorial](/lessons/compass/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
Gets the compass heading of the micro:bit in degrees
|
||||
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
```
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showString("N", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 135) {
|
||||
basic.showString("E", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 225) {
|
||||
basic.showString("S", 150)
|
||||
}
|
||||
```
|
||||
|
26
olddocs/lessons/compass/quiz.md
Normal file
26
olddocs/lessons/compass/quiz.md
Normal file
@ -0,0 +1,26 @@
|
||||
# compass quiz
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass activity](/lessons/compass/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
|
||||
|
||||
|
||||
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
|
||||
|
||||
|
||||
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
|
||||
|
||||
|
48
olddocs/lessons/counter.md
Normal file
48
olddocs/lessons/counter.md
Normal file
@ -0,0 +1,48 @@
|
||||
# counter lesson
|
||||
|
||||
Learn how to create a counter with with on button pressed.
|
||||
|
||||
## Topic
|
||||
|
||||
Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/counter/activity)
|
||||
* [challenges](/lessons/counter/challenges)
|
||||
* [quiz](/lessons/counter/quiz)
|
||||
* [quiz answers](/lessons/counter/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.compassHeading()
|
||||
basic.forever(() => {})
|
||||
let x = 0
|
||||
if (true) {}
|
||||
basic.showString("Hello!")
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
* **variable**: [read more...](/reference/variables/var)
|
||||
* **arithmetic operators**: [read more...](/reference/types/number)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)
|
||||
|
43
olddocs/lessons/counter/activity.md
Normal file
43
olddocs/lessons/counter/activity.md
Normal file
@ -0,0 +1,43 @@
|
||||
# counter activity
|
||||
|
||||
Display a number with a variable.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Let's start by creating a **local variable** `count` to keep track of the current count.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
The code under ``on button pressed("A")`` will run each time the user presses A. Let's add a line of code that increments `count` by `1`.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
})
|
||||
```
|
||||
|
||||
Since the count has changed, it's time to refresh the screen display. Let's add a line of code to display the count on screen.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/counter/challenges)
|
||||
|
||||
### ~
|
||||
|
37
olddocs/lessons/counter/challenges.md
Normal file
37
olddocs/lessons/counter/challenges.md
Normal file
@ -0,0 +1,37 @@
|
||||
# counter challenges
|
||||
|
||||
Coding challenges for the counter.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/counter/activity) At the end of the tutorial, click **keep editing**. Your code should look like this:
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add the code to `count` when `B` is pressed. Add an event handler with `on button pressed(B)` then add the code to `count`.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
count = count - 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.
|
||||
|
54
olddocs/lessons/counter/quiz-answers.md
Normal file
54
olddocs/lessons/counter/quiz-answers.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz answers
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
This is the answer key for the [counter quiz](/lessons/counter/quiz).
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
Answers may vary but a variable is a place where you can store and retrieve data
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We are only pressing on button pressed once. So the number to display on the micro:bit is also one.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the BBC micro:bit, the number 3 is displayed
|
||||
|
||||
<br/>
|
||||
|
54
olddocs/lessons/counter/quiz.md
Normal file
54
olddocs/lessons/counter/quiz.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [counter tutorial](/lessons/counter/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let counts = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counts = counts + 1
|
||||
basic.showNumber(counts, 150)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let counting= 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counting = counting + 1
|
||||
basic.showNumber(counting, 100)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
44
olddocs/lessons/dice-roll.md
Normal file
44
olddocs/lessons/dice-roll.md
Normal file
@ -0,0 +1,44 @@
|
||||
# dice roll lesson
|
||||
|
||||
Create a dice on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
If (Conditionals)
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/dice-roll/activity)
|
||||
* [challenges](/lessons/dice-roll/challenges)
|
||||
* [quiz](/lessons/dice-roll/quiz)
|
||||
* [quiz answers](/lessons/dice-roll/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a die with If statements, On Shake, Variables, Assignment Operator, Pick Random and Show LEDs
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.onGesture(Gesture.Shake, () => {})
|
||||
let x = 0
|
||||
Math.random(3)
|
||||
if (true) {}
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
* learn how to create a local variable as a place where you can store and retrieve data
|
||||
* learn how the assignment operator is used to declare a new local variable
|
||||
* learn how to declare a new local variable or update the value of a variable
|
||||
* learn how to return a random number
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show an image on the LED screen
|
169
olddocs/lessons/dice-roll/activity.md
Normal file
169
olddocs/lessons/dice-roll/activity.md
Normal file
@ -0,0 +1,169 @@
|
||||
# dice roll activity
|
||||
|
||||
Create a dice on the micro:bit
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will help you create a dice. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Let's create a condition for when the micro:bit is shaken.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
We need to show a random value from 1 to 6 on our dice. So let's make a local variable called **roll**.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6)
|
||||
})
|
||||
```
|
||||
|
||||
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `show LEDs` to display the side of a dice that shows 6.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the dice.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, ()=> {
|
||||
let roll = Math.random(6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the dice.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost done with our dice!
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #`);
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/dice-roll/challenges)!
|
||||
|
||||
### ~
|
||||
|
183
olddocs/lessons/dice-roll/challenges.md
Normal file
183
olddocs/lessons/dice-roll/challenges.md
Normal file
@ -0,0 +1,183 @@
|
||||
# dice roll challenges
|
||||
|
||||
Create a dice on the micro:bit.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/dice-roll/activity), your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #`);
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify the line of code with `pick random` so that only number 1-4 can appear on the dice.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(4);
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #`);
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's make a trick dice! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the dice. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(4) + 2;
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .`);
|
||||
}
|
||||
else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #`);
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .`);
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add a couple more conditions so that the BBC micro:bit randomly chooses a number between 1 and 8.
|
||||
|
121
olddocs/lessons/dice-roll/quiz-answers.md
Normal file
121
olddocs/lessons/dice-roll/quiz-answers.md
Normal file
@ -0,0 +1,121 @@
|
||||
# dice roll quiz answers
|
||||
|
||||
Create a dice when the BBC micro:bit is shaken
|
||||
|
||||
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
|
||||
|
||||
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let roll = Math.random(6)
|
||||
```
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let roll = Math.random(6)
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
|
||||
let roll = Math.random(6)
|
||||
if (roll == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
||||
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
let roll = Math.random(6)
|
||||
if (roll == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
||||
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
let roll = Math.random(6)
|
||||
if (roll == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
42
olddocs/lessons/dice-roll/quiz.md
Normal file
42
olddocs/lessons/dice-roll/quiz.md
Normal file
@ -0,0 +1,42 @@
|
||||
# dice roll quiz
|
||||
|
||||
Create a dice when the BBC micro:bit is shaken
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [dice roll tutorial](/lessons/dice-roll/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
37
olddocs/lessons/digi-yoyo.md
Normal file
37
olddocs/lessons/digi-yoyo.md
Normal file
@ -0,0 +1,37 @@
|
||||
# digi yoyo lesson
|
||||
|
||||
Create a counter with a while loop.
|
||||
|
||||
## Topic
|
||||
|
||||
While Loop
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/digi-yoyo/activity)
|
||||
* [challenges](/lessons/digi-yoyo/challenges)
|
||||
* [quiz](/lessons/digi-yoyo/quiz)
|
||||
* [quiz answers](/lessons/digi-yoyo/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a **while loop**, `while condition do` to repeat code while a condition is true. We will be learning how to create a digi yoyo app using a while loop, a variable, as well as basic commands, such as pause and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
let x = 0
|
||||
basic.showNumber(0)
|
||||
while (true) {}
|
||||
basic.pause(20)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a local variables to store data and use it in your code
|
||||
* learn how to set or change the value of a local variable
|
||||
* learn how to repeat code while a condition is true
|
||||
* learn how a relational comparison (<) of numbers will yield a Boolean
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
* learn how to show a number on the LED screen
|
||||
|
58
olddocs/lessons/digi-yoyo/activity.md
Normal file
58
olddocs/lessons/digi-yoyo/activity.md
Normal file
@ -0,0 +1,58 @@
|
||||
# digi yoyo activity
|
||||
|
||||
Create a counter with a while loop.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will teach how to create a counter with a while loop. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Create a variable that acts as a counter and set it to 0.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
Add a while loop that will loop over and over until the variable `count` equals 10.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
while (count < 10) {
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Let's add a pause. Then show the value of the the count.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Increase the value of count by one.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
while (count < 10) {
|
||||
basic.pause(100)
|
||||
basic.showNumber(count)
|
||||
count = count + (count - 1)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/digi-yoyo/challenges)!
|
||||
|
||||
### ~
|
||||
|
73
olddocs/lessons/digi-yoyo/challenges.md
Normal file
73
olddocs/lessons/digi-yoyo/challenges.md
Normal file
@ -0,0 +1,73 @@
|
||||
# digi yoyo challenges
|
||||
|
||||
Coding challenges for the digi yoyo.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/digi-yoyo/activity), your code should look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count);
|
||||
count = count + 1;
|
||||
basic.pause(20);
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count);
|
||||
count = count + 1;
|
||||
basic.pause(20);
|
||||
}
|
||||
while (count > 0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
|
||||
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count);
|
||||
count = count + 1;
|
||||
}
|
||||
while (count > 0) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now, we need `count` to decrease by one after the micro:bit has displayed the value of `count`.
|
||||
|
||||
We can do this by adding this line:
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
count = count + (count - 1);
|
||||
|
||||
```
|
35
olddocs/lessons/digi-yoyo/quiz-answers.md
Normal file
35
olddocs/lessons/digi-yoyo/quiz-answers.md
Normal file
@ -0,0 +1,35 @@
|
||||
# digi yoyo quiz answers
|
||||
|
||||
Answers for digi yoyo quiz.
|
||||
|
||||
This is the answer key for the [digi yoyo quiz](/lessons/digi-yoyo/quiz).
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
A loop that repeats code while a condition is true.
|
||||
|
||||
## 2. Write the code that will create a **variable** called `count` and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
## 3. Create a `while loop` that will loop until the **variable** `count` equals 4.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
while (count < 5) {
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
28
olddocs/lessons/digi-yoyo/quiz.md
Normal file
28
olddocs/lessons/digi-yoyo/quiz.md
Normal file
@ -0,0 +1,28 @@
|
||||
# digi yoyo quiz
|
||||
|
||||
Create a counter with a while loop
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digi yoyo tutorial](/lessons/digi-yoyo/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will create a variable called count and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code for a while loop that will loop until the variable count equals 4.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
39
olddocs/lessons/flashing-heart.md
Normal file
39
olddocs/lessons/flashing-heart.md
Normal file
@ -0,0 +1,39 @@
|
||||
# flashing heart blocks lesson
|
||||
|
||||
Learn how to create LED images with a global variable.
|
||||
|
||||
## Topic
|
||||
|
||||
Pause
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/lessons/flashing-heart/activity)
|
||||
* [quiz](/lessons/flashing-heart/quiz)
|
||||
* [quiz answers](/lessons/flashing-heart/quiz-answers)
|
||||
* [challenges](/lessons/flashing-heart/challenges)
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to `show LEDs` by showing an image on the LED screen. We will be learning how to create a blinking app using a forever loop as well as simple commands, such as show LEDs, pause, and clear screen.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.forever(() => {})
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
basic.pause(100)
|
||||
basic.clearScreen()
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to show LEDs on the LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
* learn how to turn off all the LED lights on the LED screen
|
71
olddocs/lessons/flashing-heart/activity.md
Normal file
71
olddocs/lessons/flashing-heart/activity.md
Normal file
@ -0,0 +1,71 @@
|
||||
# flashing heart blocks activity
|
||||
|
||||
Control images with a variable.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
In this activity, you will learn how to blink an image on the LED screen.
|
||||
|
||||
### ~
|
||||
|
||||
Let's start by adding code that plots a heart image on the screen using `show LEDs`. Once you are done coding, don't forget to run your code in the simulator or the micro:bit.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .`);
|
||||
```
|
||||
|
||||
We want to leave the image on the screen for 0.5 seconds (500 milliseconds), then clear the screen. We can use `pause` to wait and `clear screen` to turn off the LEDs.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
})
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
Finally, we can surround this code with a `forever` loop to repeat it and add a pause after `clear screen` to keep the screen off for a little while. Modify your code so that your code looks like this.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/flashing-heart/challenges)!
|
||||
|
||||
### ~
|
||||
|
96
olddocs/lessons/flashing-heart/challenges.md
Normal file
96
olddocs/lessons/flashing-heart/challenges.md
Normal file
@ -0,0 +1,96 @@
|
||||
# flashing heart blocks challenges
|
||||
|
||||
Coding challenges for the flashing heart tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [flashing heart](/lessons/flashing-heart/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's plot a different image. Let's display a broken heart!
|
||||
|
||||
To do this, you need to add a block between the last line and the end loop. Add a `show LEDs` block and then add a `pause` of 500 milliseconds.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
* click *run main* to see if the code works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's alternate flashing the heart and the broken heart. To do this, we need to add a `clear screen` block and then add a `pause` block of 500 milliseconds under the new code we added in Challenge 1.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
|
||||
* click *run main* to see if the code works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You now have a heart and broken heart flashing! Now plot a new image to alternate in with the heart and broken heart.
|
||||
|
24
olddocs/lessons/flashing-heart/quiz-answers.md
Normal file
24
olddocs/lessons/flashing-heart/quiz-answers.md
Normal file
@ -0,0 +1,24 @@
|
||||
# flashing heart blocks quiz answers
|
||||
|
||||
Learn how to create an image with a variable.
|
||||
|
||||
This is the answer key for the [flashing heart quiz](/lessons/flashing-heart/quiz).
|
||||
|
||||
## 1. Describe what pause does
|
||||
|
||||
Pause program execution for the specified number of milliseconds.
|
||||
|
||||
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
|
||||
|
||||
|
||||
```blocks
|
||||
basic.pause(1000)
|
||||
```
|
||||
|
||||
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
|
||||
|
||||
```blocks
|
||||
basic.pause(1500)
|
||||
```
|
||||
|
||||
|
25
olddocs/lessons/flashing-heart/quiz.md
Normal file
25
olddocs/lessons/flashing-heart/quiz.md
Normal file
@ -0,0 +1,25 @@
|
||||
# flashing heart blocks quiz
|
||||
|
||||
Learn how to create a blinking image with a variable.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [flashing heart activity](/lessons/flashing-heart/activity).
|
||||
|
||||
Answer the questions while completing the activity. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `pause` does?
|
||||
|
||||
|
||||
|
||||
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
|
||||
|
||||
|
||||
|
||||
|
||||
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
|
||||
|
||||
|
||||
|
30
olddocs/lessons/game-counter.md
Normal file
30
olddocs/lessons/game-counter.md
Normal file
@ -0,0 +1,30 @@
|
||||
# game counter lesson
|
||||
|
||||
Learn how to create a counter with with on button pressed.
|
||||
|
||||
## Topic
|
||||
|
||||
Game Library
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/game-counter/activity)
|
||||
* [challenges](/lessons/game-counter/challenges)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create game blocks to keep track of the current score. We will be learning how to create a game using the blocks called `add points to score`, `score` as well as simple commands such as on button pressed and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
game.addScore(1)
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
basic.showNumber(0)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a score on the LED screen
|
32
olddocs/lessons/game-counter/activity.md
Normal file
32
olddocs/lessons/game-counter/activity.md
Normal file
@ -0,0 +1,32 @@
|
||||
# game counter activity
|
||||
|
||||
Have you ever tried to create a game counter? The concept is fairly simply: increase the game `score` with `on button pressed` .
|
||||
|
||||
Let's start by adding `on button (A) pressed` will run each time the user presses A. Let's add a line of code that increments `score` by `1`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
Let's add a `add points to score` block to keep track of the current count. Since the count will change with the `add points to score` blocks, add a game block `score` to display the count on screen.
|
||||
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/game-counter/challenges)!
|
||||
|
||||
### ~
|
||||
|
37
olddocs/lessons/game-counter/challenges.md
Normal file
37
olddocs/lessons/game-counter/challenges.md
Normal file
@ -0,0 +1,37 @@
|
||||
# game counter challenges
|
||||
|
||||
Coding challenges for the game counter.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [activity](/lessons/game-counter/activity) . Your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add the code to `score` when `B` is pressed. Add an event handler with `on button (B) pressed` then add the code to `score`.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
game.addScore(1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
game.addScore(-1);
|
||||
basic.showNumber(game.score())
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.
|
||||
|
31
olddocs/lessons/game-of-chance.md
Normal file
31
olddocs/lessons/game-of-chance.md
Normal file
@ -0,0 +1,31 @@
|
||||
# game of chance blocks lesson
|
||||
|
||||
create an answering machine on the BBC micro:bit
|
||||
|
||||
## Topic
|
||||
|
||||
Game Library
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/game-of-chance/activity)
|
||||
* [challenges](/lessons/game-of-chance/challenges)
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a message with a **game over** to write your message. We will be learning how to create a message using show string and on button pressed.
|
||||
|
||||
## Documentation
|
||||
|
||||
|
||||
```cards
|
||||
game.gameOver()
|
||||
basic.showString("Hello!")
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to use the game library
|
||||
* learn how to show a string on the LED screen one character at a time
|
||||
* learn how to use to register an event handler that will execute whenever an input button is pressed
|
16
olddocs/lessons/game-of-chance/activity.md
Normal file
16
olddocs/lessons/game-of-chance/activity.md
Normal file
@ -0,0 +1,16 @@
|
||||
# game of chance blocks activity
|
||||
|
||||
Learn to create an answering machine on the micro:bit
|
||||
|
||||
We will use `show string` to show text on the LED screen. *String* is a common name for *text* in programming languages. The function `show string` scrolls the text column by column at a *150* milliseconds interval. If you want to speed up or down the scrolling, simply change the *150*.
|
||||
|
||||
```blocks
|
||||
basic.showString("SELECT A BUTTON")
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/game-of-chance/challenges)!
|
||||
|
||||
### ~
|
||||
|
48
olddocs/lessons/game-of-chance/challenges.md
Normal file
48
olddocs/lessons/game-of-chance/challenges.md
Normal file
@ -0,0 +1,48 @@
|
||||
# game of chance challenges
|
||||
|
||||
Coding challenges for the answering machine tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [game of chance](/lessons/game-of-chance/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.showString("SELECT A BUTTON")
|
||||
```
|
||||
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now we need to to play the game of chance by responding to the message. We want to respond `YOU WIN` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YOU WIN`.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("SELECT A BUTTON")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("YOU WIN")
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
What if micro:bit's answer to the question is GAME OVER? Let's have `GAME OVER` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the `GAME OVER`.
|
||||
|
||||
```blocks
|
||||
basic.showString("SELECT A BUTTON")
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("YOU WIN")
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
game.gameOver()
|
||||
})
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `TRY AGAIN`.
|
||||
|
46
olddocs/lessons/glowing-pendulum.md
Normal file
46
olddocs/lessons/glowing-pendulum.md
Normal file
@ -0,0 +1,46 @@
|
||||
# glowing pendulum blocks lesson
|
||||
|
||||
construct a pendulum that glows using acceleration.
|
||||
|
||||
## Topic
|
||||
|
||||
Acceleration
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/glowing-pendulum/activity)
|
||||
* [tutorial](/lessons/glowing-pendulum/tutorial)
|
||||
* [challenges](/lessons/glowing-pendulum/challenges)
|
||||
* [quiz](/lessons/glowing-pendulum/quiz)
|
||||
* [quiz answers](/lessons/glowing-pendulum/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to get the acceleration **acceleration**, `acceleration` value (g-force), in one of three specified dimensions. We will be learning how to get the acceleration using forever loop, a local variable, acceleration, the math library, as well as simple commands, such as led set brightness and led plot all.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
basic.forever(() => {})
|
||||
let x = 0
|
||||
input.acceleration(Dimension.X)
|
||||
Math.abs(0)
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how create a local variable to store data, so that you can use it in your code
|
||||
* learn how to get the acceleration value (g-force), in one of three specified dimensions
|
||||
* learn how to return the absolute value
|
||||
* learn how to sets the brightness of the LED screen
|
||||
* learn how to turn on all the LED lights on the LED screen
|
||||
|
108
olddocs/lessons/glowing-pendulum/activity.md
Normal file
108
olddocs/lessons/glowing-pendulum/activity.md
Normal file
@ -0,0 +1,108 @@
|
||||
# glowing pendulum block activity
|
||||
|
||||
Construct a pendulum that glows using acceleration.
|
||||
|
||||
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
|
||||
|
||||
Turn on all the LEDs.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
});
|
||||
```
|
||||
|
||||
Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration)
|
||||
});
|
||||
```
|
||||
|
||||
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Now let's use our acceleration value to set the brightness on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
});
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/glowing-pendulum/challenges)!
|
||||
|
||||
### ~
|
||||
|
36
olddocs/lessons/glowing-pendulum/challenges.md
Normal file
36
olddocs/lessons/glowing-pendulum/challenges.md
Normal file
@ -0,0 +1,36 @@
|
||||
# glowing pendulum blocks challenges
|
||||
|
||||
Coding challenges for the glowing pendulum tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||

|
||||
|
||||
Hold the micro:bit in your hand in a dark room. Move the micro:bit like a pendulum and produce a slow image that captures the pattern of the micro:bit LEDs.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Replace "y" in `acceleration(y)` with "x" or "z". Changing the axis will cause the micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make?
|
||||
|
46
olddocs/lessons/glowing-pendulum/quiz-answers.md
Normal file
46
olddocs/lessons/glowing-pendulum/quiz-answers.md
Normal file
@ -0,0 +1,46 @@
|
||||
# glowing pendulum quiz answers
|
||||
|
||||
construct a pendulum that glows using acceleration.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let acceleration = input.acceleration("y")
|
||||
```
|
||||
|
||||
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let acceleration = input.acceleration(Dimension.X)
|
||||
let accelerationAbsolute = Math.abs(acceleration)
|
||||
```
|
||||
|
||||
## 4. Write the code to use the acceleration value from question 3 to set the brightness on the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let accelerationX = input.acceleration(Dimension.X)
|
||||
let accelerationAbsolute = Math.abs(accelerationX)
|
||||
let accelerationDivided = accelerationX / 4
|
||||
led.setBrightness(accelerationX)
|
||||
```
|
||||
|
27
olddocs/lessons/glowing-pendulum/quiz.md
Normal file
27
olddocs/lessons/glowing-pendulum/quiz.md
Normal file
@ -0,0 +1,27 @@
|
||||
# glowing pendulum quiz
|
||||
|
||||
construct a pendulum that glows using acceleration.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code to include acceleration value question 3 to set the brightness on the BBC micro:bit.
|
||||
|
||||
|
29
olddocs/lessons/glowing-pendulum/tutorial.md
Normal file
29
olddocs/lessons/glowing-pendulum/tutorial.md
Normal file
@ -0,0 +1,29 @@
|
||||
# glowing pendulum block tutorial
|
||||
|
||||
The glowing pendulum changes the screen brightness based on the acceleration measured on the BBC micro:bit.
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* all LEDs are turned on
|
||||
* the BBC micro:bit repeats code **forever** that
|
||||
* reads the acceleration along the ``y`` axis,
|
||||
* calculate the absolute value of the acceleration
|
||||
* scales down the acceleration value by a factor of `4`
|
||||
* uses the scaled value to set the screen **brightness**
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration);
|
||||
acceleration = acceleration / 4;
|
||||
led.setBrightness(acceleration)
|
||||
});
|
||||
```
|
64
olddocs/lessons/graphics.md
Normal file
64
olddocs/lessons/graphics.md
Normal file
@ -0,0 +1,64 @@
|
||||
# blocks - rendering graphics
|
||||
|
||||
An introduction to graphics for the Block Editor.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Ensure you have completed the 'Hello, world!' and Loop tutorials and tested them on a simulator or on BBC micro:bit.
|
||||
|
||||

|
||||
|
||||
The BBC micro:bit has a grid of 25 LEDs, so we can use these to display images.
|
||||
|
||||
We’ve already experimented with the `show string` block that displays a string (some text) that we program it to. However we can use more blocks from the **Images** drawer to render or display images in different ways.
|
||||
|
||||
### Pixel Art
|
||||
|
||||
We can draw little images from the LEDs by ticking boxes. Drag a `show image` block from the **Images** drawer and connect in a `create image` block. You can customize this image by clicking boxes to tick whether the LED will turn on or off. For example, if we were creating a music player we may want to the show the `play` block:
|
||||
|
||||

|
||||
|
||||
### Plotting points
|
||||
|
||||
We can also code our bug to plot a point by giving an x (horizontal) and y (vertical) coordinates, from 0 to 4. Click the **LED** drawer and drag a `plot` block. Try changing the coordinates and see the effect this has on the BBC micro:bit.
|
||||
|
||||
We can also unplot a point (turn the LED off again) using the `unplot` block. So we could create a flashing LED program, using the `pause` block to create a delay.
|
||||
|
||||

|
||||
|
||||
We can also use the `clear screen` block to turn off all LEDs.
|
||||
|
||||
## Tip
|
||||
|
||||
The pause block is in milliseconds, so setting it to 1000 will have a pause of a single second.
|
||||
|
||||
### Devising algorithms for shapes
|
||||
|
||||
An algorithm is a set of steps to follow to solve a problem. We can begin to draw shapes on the BBC micro:bit using an algorithm. For example, we could draw a straight line with this code:
|
||||
|
||||

|
||||
|
||||
Our algorithm is: increase **i** by 1 **from 0** to **4**, and **plot** the point **x=i**, **y=0**. The pause block allows this line to be animated (drawn frame by frame).
|
||||
|
||||
Try devising an algorithm for a diagonal line using the code above and the variable **i**. Your code should look like this; as our variable increases, so does the location that the BBC micro:bit is plotting at:
|
||||
|
||||

|
||||
|
||||
We can create more complex algorithms for more complex shapes, too. See the [challenges](/lessons/challenges) section for additional graphical challenges and solutions.
|
||||
|
||||
### Animations
|
||||
|
||||
Animations are changes happening at a certain rate. For example, we could add the `delay` block from the **Basic** drawer with our square algorithm – this will slowly draw a square (as an animation).
|
||||
|
||||
We could create more complex animations, for example we could make our BBC micro:bit display an explosion or fireworks.
|
||||
|
||||
See the [challenges](/lessons/challenges) section for some animation tasks.
|
||||
|
||||
### Image variables
|
||||
|
||||
We can create image variables so we can easily display an image at a later point. For example:
|
||||
|
||||

|
||||
|
||||
This uses the blocks from the **Variable** drawer, and the **create image** block from the **Image** drawer. This means our image can be displayed without having to replicate the `create image` block each time.
|
||||
|
38
olddocs/lessons/guess-the-number.md
Normal file
38
olddocs/lessons/guess-the-number.md
Normal file
@ -0,0 +1,38 @@
|
||||
# guess the number lesson
|
||||
|
||||
Learn to create a random number with input from button A.
|
||||
|
||||
## Topic
|
||||
|
||||
Math - Pick Random
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/lessons/guess-the-number/activity)
|
||||
* [tutorial](/lessons/guess-the-number/tutorial)
|
||||
* [challenges](/lessons/guess-the-number/challenges)
|
||||
* [quiz](/lessons/guess-the-number/quiz)
|
||||
* [quiz answers](/lessons/guess-the-number/quiz-answers)
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create numbers randomly by using the input of the BBC micro:bit. We will be learning how to create random numbers with input using a local variable as well as simple commands, such as pick number and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
input.onButtonPressed(Button.A, () => {})
|
||||
let x = 0
|
||||
basic.showNumber(0)
|
||||
Math.random(3)
|
||||
basic.clearScreen()
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how a variable is a place where you can store data
|
||||
* learn how to set the value of a local variable
|
||||
* learn how to returns a random number
|
||||
* learn how to show a number on the LED screen, one digit at a time (scrolling left to right)
|
||||
* learn how to turn off all the LED lights on the LED screen
|
45
olddocs/lessons/guess-the-number/activity.md
Normal file
45
olddocs/lessons/guess-the-number/activity.md
Normal file
@ -0,0 +1,45 @@
|
||||
# guess the number activity
|
||||
|
||||
Guess the number with math random.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will help you create a guess the number game! Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Add an event handler when button `A` is pressed.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Create a local variable of type number `x` and set it to a random number using `pick random`. `pick random` 9 generates a random number between `0` and `9`.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
Show the random number on the screen.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/guess-the-number/challenges)!
|
||||
|
||||
### ~
|
||||
|
33
olddocs/lessons/guess-the-number/challenges.md
Normal file
33
olddocs/lessons/guess-the-number/challenges.md
Normal file
@ -0,0 +1,33 @@
|
||||
# guess the number challenges
|
||||
|
||||
Coding challenges for the guess the number tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/guess-the-number/activity), and your code should look like this:
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(9)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Show an animation when you clear the screen! Choose what animation makes most sense to you. Be creative!
|
||||
|
41
olddocs/lessons/guess-the-number/quiz-answers.md
Normal file
41
olddocs/lessons/guess-the-number/quiz-answers.md
Normal file
@ -0,0 +1,41 @@
|
||||
# guess the number quiz answers
|
||||
|
||||
Learn how to generate a random number on the micro:bit.
|
||||
|
||||
This is the answer key for the [guess the number quiz](/lessons/guess-the-number/quiz).
|
||||
|
||||
## 1. What is on button pressed?
|
||||
|
||||
Answers may vary. Generally, on button pressed run code when an input button is pressed. The micro:bit has two input buttons: A and B.
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
Write the line of code that creates a condition when the BBC micro:bit button A is pressed.
|
||||
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## 3. Write the line of code that creates a **local variable** and a **random number**.
|
||||
|
||||
|
||||
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
```
|
||||
|
||||
## 4.
|
||||
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
The random number generator will return a number from 0 to the limit. However, not including the limit unless the limit is 0. So you can place an X to represent any single digit number.
|
||||
|
35
olddocs/lessons/guess-the-number/quiz.md
Normal file
35
olddocs/lessons/guess-the-number/quiz.md
Normal file
@ -0,0 +1,35 @@
|
||||
# guess the number quiz
|
||||
|
||||
Learn how to generate a random number on the micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [guess the number tutorial](/lessons/guess-the-number/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "input -> on button pressed" does?
|
||||
|
||||
<br />
|
||||
|
||||
## 2. Write the line of code that creates a condition for on button A pressed.
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the line of code that creates a `local variable` called `randomNumber` and will return a number from 0 to a limit of 10.
|
||||
|
||||
<br />
|
||||
|
||||
## 4. Draw the area that could be lit based on the code below. Explain why you chose to draw that number.
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.random(10)
|
||||
basic.showNumber(randomNumber, 150)
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
23
olddocs/lessons/guess-the-number/tutorial.md
Normal file
23
olddocs/lessons/guess-the-number/tutorial.md
Normal file
@ -0,0 +1,23 @@
|
||||
# guess the number tutorial
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
This tutorial will help you create a guess the number game! Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* when the user presses button ``A``,
|
||||
* generate a random number
|
||||
* show the number on screen
|
||||
|
||||
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x)
|
||||
})
|
||||
```
|
||||
|
28
olddocs/lessons/happy-birthday.md
Normal file
28
olddocs/lessons/happy-birthday.md
Normal file
@ -0,0 +1,28 @@
|
||||
# happy birthday blocks lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Music
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/happy-birthday/activity)
|
||||
* [challenges](/lessons/happy-birthday/challenges)
|
||||
|
||||
## 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). We will be learning how to code musical notes using simple commands such as play, keys, and notes.
|
||||
|
||||
## What the teacher needs to know / QuickStart Computing Glossary
|
||||
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to code music on the BBC micro:bit
|
||||
* learn how to setup the BBC micro:bit as a music player
|
56
olddocs/lessons/happy-birthday/activity.md
Normal file
56
olddocs/lessons/happy-birthday/activity.md
Normal file
@ -0,0 +1,56 @@
|
||||
# happy birthday blocks activity
|
||||
|
||||
Play sounds with music blocks.
|
||||
|
||||
Have you ever tried to play a song on an instrument? Let's try coding the song "Happy Birthday" on the micro:bit !
|
||||
|
||||
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 micro:bit.
|
||||
|
||||
```blocks
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
```
|
||||
|
||||
* 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
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
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
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
```
|
||||
|
||||
|
||||
* click run to see if the code works as expected.
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/happy-birthday/challenges)!
|
||||
|
||||
### ~
|
||||
|
106
olddocs/lessons/happy-birthday/challenges.md
Normal file
106
olddocs/lessons/happy-birthday/challenges.md
Normal file
@ -0,0 +1,106 @@
|
||||
# happy birthday blocks challenges
|
||||
|
||||
Coding challenges for finishing the song, happy birthday.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [happy birthday](/lessons/happy-birthday/activity) activity and your code will look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
|
||||
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's code the third part of Happy Birthday!
|
||||
|
||||
To do this, you need to add blocks after the last line of the `play` blocks. We want to continue to adding musical chords with the `play` block. Then insert the appropriate chord blocks `G`, `E`, `C`, `B`, `A` to complete the third part of the song. Modify your code so that your code looks like this.
|
||||
|
||||
``` blocks
|
||||
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
|
||||
```
|
||||
|
||||
* click *run * to see if the code works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Finally, we continue to adding the appropriate `play` block and fit the following chords blocks `F`, `E`, `C`, `D` to complete the third part of the song. Modify your code so that your code looks like this.
|
||||
|
||||
|
||||
```blocks
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
|
||||
basic.pause(100);
|
||||
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.B), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
|
||||
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
|
||||
```
|
||||
|
||||
|
||||
* click *run * to see if the code works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You now have a the ability to create music on the micro:bit. Try to code another favourite song.
|
||||
|
130
olddocs/lessons/headbands.md
Normal file
130
olddocs/lessons/headbands.md
Normal file
@ -0,0 +1,130 @@
|
||||
# headbands lesson
|
||||
|
||||
create a charades game that can be played with your friends.
|
||||
|
||||
## Topic
|
||||
|
||||
Collection
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/headbands/activity)
|
||||
* [quiz](/lessons/headbands/quiz)
|
||||
* [quiz answers](/lessons/headbands/quiz-answers)
|
||||
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a charades game with **collections**, ` create -> Collection of` , to store and retrieve data . We will be learning how to create a charades game using global variables, collection of string, add, Boolean, on logo down, on logo up, forever loop, if statements, running time as well as simple commands, such as show string and show number.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **collection**
|
||||
* **global variables** : [read more...](/reference/variables/globals.md)
|
||||
* **Boolean** : [read more...](/reference/types/boolean)
|
||||
* **on logo up** [read more...](/functions/on-logo-up)
|
||||
* **on screen down** [read more...](/functions/on-screen-down)
|
||||
* **on screen up** [read more...](/functions/on-screen-up)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **game library** : [read more...](/reference/game-library)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/headbands/activity)
|
||||
* Activity: [quiz](/lessons/headbands/quiz)
|
||||
* Extended Activity: [challenges](/lessons/headbands/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how a collection is a group of variables of the same type stored together
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to run code when the BBC micro:bit is oriented perpendicular to the floor with the logo down
|
||||
* learn how to get the number of milliseconds elapsed since the script began
|
||||
* learn how to show a string on the BBC micro:bit screen
|
||||
* learn how to show a number of the BBC micro:bit screen
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* 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)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/headbands/activity)
|
||||
* [quiz](/lessons/headbands/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/headbands/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/headbands/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
89
olddocs/lessons/headbands/activity.md
Normal file
89
olddocs/lessons/headbands/activity.md
Normal file
@ -0,0 +1,89 @@
|
||||
# headbands activity
|
||||
|
||||
## Before we get started
|
||||
|
||||
Your beginning code should look like this:
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add more words for the player to act out! But first, we need to increase the time in one round to give the player more time get through all the words. Let's change the `game->start countdown` statement.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
|
||||
game.startCountdown(60000)
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's add 5 more words to our list of charade words. Right above the the line `word:=coll->at(index)` add 5 lines that say `coll->add("")`. In this example, we will add the words **bicycle, telephone, sun, car, and ant** but you can add whatever words you like.
|
||||
|
||||
```blocks
|
||||
let coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
coll.push("bicycle")
|
||||
coll.push("telephone")
|
||||
coll.push("sun")
|
||||
coll.push("car")
|
||||
coll.push("ant")
|
||||
input.onLogoUp(() => {
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Remove a life using `game->remove life` when the screen is down using the `input->on screen down` event.
|
||||
|
||||
### Challenge 4
|
||||
|
||||
The collection has a function `random` that returns a random element. Update your code to use this function instead of using `math->random`.
|
||||
|
||||
### Challenge 5!
|
||||
|
||||
Play the game and try guessing all these words in less than 2 minutes!
|
||||
|
78
olddocs/lessons/headbands/quiz-answers.md
Normal file
78
olddocs/lessons/headbands/quiz-answers.md
Normal file
@ -0,0 +1,78 @@
|
||||
# headbands quiz answers
|
||||
|
||||
create a charades game with a collection of strings.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [headbands tutorial](/lessons/headbands/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the meaning of the term 'collection' in programming? What is a 'collection' of strings?
|
||||
|
||||
<br/>
|
||||
|
||||
A 'collection' is a group of variables of the same type stored together. A 'collection' of strings is a group of strings stored together.
|
||||
|
||||
## 2. Consider the following lines of code.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "puppy" using `data->coll`.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
basic.showString(coll[0], 150)
|
||||
```
|
||||
|
||||
## 3. Consider the following lines of code.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("cat")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "cat" using `data->coll`.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
basic.showString(coll[2], 150)
|
||||
```
|
||||
|
||||
## 4. Consider the following line of code.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
```
|
||||
|
||||
Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
```
|
||||
|
||||
## 5. Write the code to get a string from the collection at a random position.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let index = Math.random(coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
63
olddocs/lessons/headbands/quiz.md
Normal file
63
olddocs/lessons/headbands/quiz.md
Normal file
@ -0,0 +1,63 @@
|
||||
# headbands quiz
|
||||
|
||||
create a charades game with a collection of strings.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [headbands tutorial](/lessons/headbands/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the meaning of the term 'collection' in programming? What is a 'collection' of strings?
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code that will display the string "puppy" using "data->coll".
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the line of code that will display the string "cat" using `"data->coll".
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("cat")
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
```
|
||||
let coll = (<string[]>[])
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code to get a string from the collection at a random position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
7
olddocs/lessons/hero.md
Normal file
7
olddocs/lessons/hero.md
Normal file
@ -0,0 +1,7 @@
|
||||
# hero
|
||||
|
||||
make a game to test hand-eye coordination.
|
||||
|
||||
Make a game to test hand-eye coordination
|
||||
|
||||
* [activity](/lessons/hero/activity)
|
278
olddocs/lessons/hero/activity.md
Normal file
278
olddocs/lessons/hero/activity.md
Normal file
@ -0,0 +1,278 @@
|
||||
# hero
|
||||
|
||||
A classic game, Hero, in which you must capture the food and flee away from the ghost!
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
This tutorial will teach you how to create a hero game to capture food while dodging the ghost; the game was inspired by the classic arcade game Pac Man.
|
||||
|
||||
### ~
|
||||
|
||||
First we need to create a function create sprite at the x, y coordinates and that set the variable called hero on the micro:bit the first time we play.
|
||||
|
||||
|
||||
```blocks
|
||||
|
||||
let hero = game.createSprite(2, 2)
|
||||
|
||||
```
|
||||
|
||||
Let's set up where we want our ghost will be. Create starting positions of the hero, ghost, and food in each individual quadrant. We will ensure that the ghost, food, and hero is set apart. Divide the micro:bit into 4 quadrants. We don't want hero to be too close to the ghost so let's make the ghost starting positions in the 3 other quadrants. Hero is in the one quadrant. To do this, we need to keep track of the middle point in each quadrant. Create sprite at the x, y coordinates for the hero, food, and ghost.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2)
|
||||
let food = game.createSprite(4, 4)
|
||||
let ghost = game.createSprite(0, 0)
|
||||
```
|
||||
|
||||
|
||||
Create a function called change blink that will plot a blinking point so the player can tell between a ghost and hero.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
|
||||
```
|
||||
|
||||
|
||||
We want to identify the food so the player moves towards the food. We need to set the `brightness` of the `variable` food to 8. The brightness of the LED screen is expressed as a number between 0 and 255.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
|
||||
```
|
||||
|
||||
We want to include a block from the Loops drawer called `While`. Then set the `While` loop to `true`. This code will be important for repeating code of the game logic of the game. The game will continue to run using `While` loop while the Boolean condition is true. Finally, include a `pause` of 400 milliseconds before the logic of the game begins.
|
||||
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Let's create a function that will take care of keep the ghost pursuing the hero. We will need to a conditional statement that checks the position of the ghost and hero. The first condition will check if the horizontal coordinates of the ghost is less than the horizontal coordinates of the hero. We create a function from the Game drawer that will check the coordinates of the hero and the ghost. Finally, change the x-direction of the ghost by 1.
|
||||
|
||||
Then create another function that will take care of keep the ghost pursuing the hero. We will need to a conditional statement that checks the position of the ghost and hero. The second condition will check if the horizontal coordinates of the ghost is greater than the x-direction of hero. We create a function from the Game drawer that will check the x-direction of hero and ghost. Finally, change the x-direction of the ghost by -1.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.X) > hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
else if (false) {
|
||||
}
|
||||
else if (false) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Let's create the third function and forth function that continues the same logic in the y-direction of pacman and ghost. We create a function from the Game drawer that will check the y-direction of pacman and ghost. Finally, change the y-direction of the ghost to continue following pacman.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) < hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Let's enable pacman to move in the x-direction and move in the y-direction with acceleration using the micor:bit sensor
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) < hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.X) > 200) {
|
||||
hero.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.X) < -200 ) {
|
||||
hero.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.Y) > 200) {
|
||||
hero.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.Y) > -200 ) {
|
||||
hero.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Let's setup the logic for the food. If hero is `touching` "food", increase the score of the game by 1 and `set` ``x`` -direction of food randomly randomly from 0 to 4 and `set` ``y``-direction of food randomly from 0 to 4.
|
||||
|
||||
```blocks
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) < hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.X) > 200) {
|
||||
hero.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.X) < -200 ) {
|
||||
hero.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.Y) > 200) {
|
||||
hero.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.Y) > -200 ) {
|
||||
hero.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.random(5));
|
||||
food.set(LedSpriteProperty.Y, Math.random(5));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
Let's setup the logic for the food and the ghost to be in different quadrants. Finally, the game over component is now upon the game. If the hero is `touching` the ghost, let's display `game over`
|
||||
|
||||
```blocks
|
||||
|
||||
let hero = game.createSprite(2, 2);
|
||||
let food = game.createSprite(4, 4);
|
||||
let ghost = game.createSprite(0, 0);
|
||||
let ghost.change(LedSpriteProperty.Blink, 100);
|
||||
food = led.brightness() == 8;
|
||||
while (true) {
|
||||
basic.pause(400);
|
||||
if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.X) < hero.get(LedSpriteProperty.X)) {
|
||||
ghost.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) < hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (ghost.get(LedSpriteProperty.Y) > hero.get(LedSpriteProperty.Y)) {
|
||||
ghost.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.X) > 200) {
|
||||
hero.change(LedSpriteProperty.X, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.X) < -200 ) {
|
||||
hero.change(LedSpriteProperty.X, -1 );
|
||||
}
|
||||
if (input.acceleration(Dimension.Y) > 200) {
|
||||
hero.change(LedSpriteProperty.Y, 1);
|
||||
}
|
||||
else if (input.acceleration(Dimension.Y) > -200 ) {
|
||||
hero.change(LedSpriteProperty.Y, -1 );
|
||||
}
|
||||
if (hero.isTouching(food)) {
|
||||
game.addScore(1);
|
||||
food.set(LedSpriteProperty.X, Math.random(5));
|
||||
food.set(LedSpriteProperty.Y, Math.random(5));
|
||||
if (food.get(LedSpriteProperty.X) < 2 && food.get(LedSpriteProperty.Y) < 2) {
|
||||
ghost.set(LedSpriteProperty.X, 4);
|
||||
ghost.set(LedSpriteProperty.Y, 4);
|
||||
}
|
||||
else if (food.get(LedSpriteProperty.X) > 2 && food.get(LedSpriteProperty.Y) < 2) {
|
||||
ghost.set(LedSpriteProperty.X, 0);
|
||||
ghost.set(LedSpriteProperty.Y, 4);
|
||||
}
|
||||
else if (food.get(LedSpriteProperty.X) < 2 && food.get(LedSpriteProperty.Y) > 2) {
|
||||
ghost.set(LedSpriteProperty.X, 4);
|
||||
ghost.set(LedSpriteProperty.Y, 0);
|
||||
}
|
||||
else {
|
||||
ghost.set(LedSpriteProperty.X, 0);
|
||||
ghost.set(LedSpriteProperty.Y, 0);
|
||||
}
|
||||
}
|
||||
if (hero.isTouching(ghost)) {
|
||||
game.gameOver();
|
||||
}
|
||||
|
||||
}
|
||||
0.set(LedSpriteProperty.X, 4);
|
||||
|
||||
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Congratulations! You have a homemade hero game based on the classic version of PacMan
|
||||
|
||||
### ~
|
||||
|
40
olddocs/lessons/looper.md
Normal file
40
olddocs/lessons/looper.md
Normal file
@ -0,0 +1,40 @@
|
||||
# looper blocks lesson
|
||||
|
||||
Learn to control blinking LEDs.
|
||||
|
||||
## Topic
|
||||
|
||||
For Loop
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/lessons/looper/activity)
|
||||
* [challenges](/lessons/looper/challenges)
|
||||
* [quiz](/lessons/looper/quiz)
|
||||
* [quiz answers](/lessons/looper/quiz-answers)
|
||||
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED. We will be learning how to create a blinking app using the for loop as well as simple commands, such as plot and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
for (let i = 0; i < 5; i++) {}
|
||||
basic.showNumber(0)
|
||||
basic.pause(100)
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code a fixed number of times
|
||||
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)
|
||||
* learn how to pause program execution for the specified number of milliseconds
|
||||
* learn how to arithmetic operators operate on numbers and return a number
|
36
olddocs/lessons/looper/activity.md
Normal file
36
olddocs/lessons/looper/activity.md
Normal file
@ -0,0 +1,36 @@
|
||||
# looper blocks activity
|
||||
|
||||
Welcome! This activity will teach how to display a series of numbers for a for loop. Let's get started!
|
||||
|
||||
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `5` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 5`.
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
We will show the number of times the loop has been executed. It will go from zero to five times.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
```
|
||||
|
||||
The for loop while cycle through to six immediately unless we pause for a little bit in between each loop.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/looper/challenges)!
|
||||
|
||||
### ~
|
||||
|
85
olddocs/lessons/looper/challenges.md
Normal file
85
olddocs/lessons/looper/challenges.md
Normal file
@ -0,0 +1,85 @@
|
||||
# looper block challenges
|
||||
|
||||
Coding challenges for the looper.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided activity:
|
||||
|
||||
* [activity](/lessons/looper/activity)
|
||||
|
||||
At the end of the activity, your code should look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
What if we want to count up to lucky number 7 instead? Let's do that by changing the ending value to `7` instead of `5`.
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 8; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
* Run the program now to see your changes.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
What about 9? Let's do that by changing the ending value to `9`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see the new counter.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's start counting from `3` instead! Our for loop will always start at `0` so we simply add `3` to the `i` variable when passing it to `show number`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(i+3)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Run it on the simulator!
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Now, let's **count down from 9**. Change the line `show number(i + 2, 150)` to `show number(9 - i, 150)`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(9-i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
* Run the code to make sure it is doing what is expected.
|
||||
|
||||
### Challenge 5
|
||||
|
||||
After counting down from `9` let's show the string `BOOOM`!
|
||||
|
40
olddocs/lessons/looper/quiz-answers.md
Normal file
40
olddocs/lessons/looper/quiz-answers.md
Normal file
@ -0,0 +1,40 @@
|
||||
# looper quiz answers
|
||||
|
||||
Learn how to create a series of numbers with a for loop.
|
||||
|
||||
This is the answer key for the [looper quiz](/lessons/looper/quiz).
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 4; i++) {
|
||||
basic.showNumber(i, 150)
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
|
||||
|
||||
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `4` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 4`.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```blocks
|
||||
for (let i1 = 0; i1 < 6; i1++) {
|
||||
basic.showNumber(i1, 150)
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
|
||||
|
||||
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `6` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 6`.
|
||||
|
||||

|
||||
|
||||

|
||||
|
42
olddocs/lessons/looper/quiz.md
Normal file
42
olddocs/lessons/looper/quiz.md
Normal file
@ -0,0 +1,42 @@
|
||||
# looper quiz
|
||||
|
||||
Learn how to create a series of numbers with a for loop.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [looper tutorial](/lessons/looper/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what a "for loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw the areas where the LEDs will be lit based on the code below. Explain why you chose to draw those numbers.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 4; i++) {
|
||||
basic.showNumber(i, 150)
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw the areas where the LEDs will be lit based on the code below. Explain why you chose to draw those numbers.
|
||||
|
||||
```blocks
|
||||
for (let i1 = 0; i1 < 6; i1++) {
|
||||
basic.showNumber(i1, 150)
|
||||
}
|
||||
```
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
59
olddocs/lessons/loops.md
Normal file
59
olddocs/lessons/loops.md
Normal file
@ -0,0 +1,59 @@
|
||||
# blocks - loops
|
||||
|
||||
An introduction to Loops for the Block Editor.
|
||||
|
||||
We may want to handle the user’s input multiple times or remain waiting for their input for a long time. We use loops to make sure that our code runs multiple times. These can be found in the **Loops** drawer.
|
||||
|
||||
### Forever loops
|
||||
|
||||
In the Variables tutorial we utilised a forever loop to create a counter:
|
||||
|
||||

|
||||
|
||||
This allows our BBC micro:bit to wait for the user to do something forever, for example wait for the user to press the correct button as the example above shows. If you were creating a quiz, you may want to loop forever until the user presses the correct button or answers the question.
|
||||
|
||||
### Repeat Loops
|
||||
|
||||
Repeat loops allow code to happen a certain amount of times. You may want to create a quiz that only gives the user a few tries to get the correct answer, for example. The number can be changed to facilitate your code.
|
||||
|
||||

|
||||
|
||||
The code above will scroll the message, “Hello world” three times.
|
||||
|
||||
### While & Until loops
|
||||
|
||||
The ‘repeat while’ loop allows you to continue looping some code until a condition is met. The empty socket next to the while loop allows you to connect some Logic and construct a statement.
|
||||
|
||||

|
||||
|
||||
The code above will scroll the message, “Press it!”, while the user hasn’t pressed the button.
|
||||
|
||||
* Drag a `set item` block from the **Variables** drawer. Click the **down arrow** and click **New Variable**, and type "pressed". Drag a `0` block from **Maths** to set the variable **pressed** to 0.
|
||||
* Drag a `repeat while` block from the **Loops** drawer and attach an `=` block from the **Logic** drawer. Drag `item` from the **Variables** drawer and click the **down arrow**, select ‘pressed’. Drag a `0` block from Maths and connect it to the other side of the equals. This will carry out the code until ‘pressed’ does not equal 0.
|
||||
* Add a `show string` block from the **Basic** drawer and change the message to "Press it!"
|
||||
* Add an `if` block from the **Logic** drawer, connect a `button pressed` block from the **Input** drawer, and add text from the **Basic** drawer. Change this to A to show we are waiting for button A.
|
||||
* Inside the ‘do’ part of the if statement, add a `set` block from the Variables drawer, click the **down arrow** to change it to **pressed** and drag a `1` from the Maths drawer
|
||||
* Lastly underneath the while loop, add another `show string` block and fill in the gaps.
|
||||
|
||||
Test the code above on actual hardware or on the simulator window.
|
||||
|
||||
We can also change the code in subtle ways to have a completely different effect:
|
||||
|
||||

|
||||
|
||||
This time we have to press the button three times to leave the while loop.
|
||||
|
||||
## Tip
|
||||
|
||||
You can press the arrow next to a word in a block to change it. For example, you can change Math functions or change a Logic statement.
|
||||
|
||||
### Count or for loops
|
||||
|
||||
A count loop allows you to loop a certain amount of times and to change a variable as you do so. For example, we can create a simple counting program:
|
||||
|
||||

|
||||
|
||||
The count loop will repeat a certain amount of times whilst changing a variable. You can click the arrow next to **i** to replace it with any of your own variables. So this program will display numbers 1 to 10.
|
||||
|
||||
This loop allows you to repeat code for the amount of times you want to without worrying about manually changing variables. You could use this for a counting program or a timer.
|
||||
|
30
olddocs/lessons/love-meter.md
Normal file
30
olddocs/lessons/love-meter.md
Normal file
@ -0,0 +1,30 @@
|
||||
# love meter blocks lesson
|
||||
|
||||
Create a love meter with the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
On Pin Pressed
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/love-meter/activity)
|
||||
* [quiz](/lessons/love-meter/quiz)
|
||||
* [quiz answers](/lessons/love-meter/quiz-answers)
|
||||
* [challenges](/lessons/love-meter/challenges)
|
||||
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to use the **pin pressed**, `on pin pressed` to run code when the user holds the GND pin with one hand, and presses pin 0 with the other hand, thus completing a circuit. We will be learning how to create a love meter using input on pin pressed, a local variable, math random, If (conditional) as well as simple commands, such as show number, pause, and show string.
|
||||
|
||||
## Documentation
|
||||
|
||||
```cards
|
||||
if (true) {}
|
||||
input.onPinPressed(TouchPin.P0, () => {})
|
||||
let x = 0
|
||||
Math.random(3)
|
||||
basic.showNumber(0)
|
||||
basic.pause(100)
|
||||
```
|
47
olddocs/lessons/love-meter/activity.md
Normal file
47
olddocs/lessons/love-meter/activity.md
Normal file
@ -0,0 +1,47 @@
|
||||
# love meter blocks activity
|
||||
|
||||
Create a love meter with the micro:bit
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This activity will help you create a love meter with the micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
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](/lessons/love-meter/challenges)
|
||||
|
||||
### ~
|
||||
|
69
olddocs/lessons/love-meter/challenges.md
Normal file
69
olddocs/lessons/love-meter/challenges.md
Normal file
@ -0,0 +1,69 @@
|
||||
# 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](/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
|
||||
|
||||
**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.
|
||||
|
46
olddocs/lessons/love-meter/quiz-answers.md
Normal file
46
olddocs/lessons/love-meter/quiz-answers.md
Normal file
@ -0,0 +1,46 @@
|
||||
# love meter blocks quiz answers
|
||||
|
||||
The answers to the love meter quiz.
|
||||
|
||||
This is the answer key for the [love meter quiz](/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)`.
|
||||
|
||||
```blocks
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## 3. What does this line of code doing?
|
||||
|
||||
```blocks
|
||||
let x = Math.random(9)
|
||||
```
|
||||
|
||||
|
||||
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?
|
||||
|
||||
```blocks
|
||||
let item = 0;
|
||||
item = 0;
|
||||
basic.showNumber(item + 1);
|
||||
```
|
||||
|
||||
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?
|
||||
|
||||
|
||||
You have told GND to complete the circuit.
|
||||
|
39
olddocs/lessons/love-meter/quiz.md
Normal file
39
olddocs/lessons/love-meter/quiz.md
Normal file
@ -0,0 +1,39 @@
|
||||
# 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](/lessons/love-meter/activity).
|
||||
|
||||
Answer the questions below while completing the activity. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `on pin pressed` does?
|
||||
|
||||
|
||||
## 2. Create a condition for on pin pressed (P0).
|
||||
|
||||
|
||||
## 3. Describe what this line of code does?
|
||||
|
||||
```blocks
|
||||
let x = Math.random(9)
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 4. Describe what adding 1 to variable x does?
|
||||
|
||||
```blocks
|
||||
let item = 0;
|
||||
item = 0;
|
||||
basic.showNumber(item + 1);
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using `on pin pressed(P0)` on the micro:bit
|
||||
|
||||
|
20
olddocs/lessons/lucky-7.md
Normal file
20
olddocs/lessons/lucky-7.md
Normal file
@ -0,0 +1,20 @@
|
||||
# lucky 7 blocks lesson
|
||||
|
||||
Show a number on the LED screen.
|
||||
|
||||
## Topic
|
||||
|
||||
Show Number
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/lucky-7/activity)
|
||||
* [quiz](/lessons/lucky-7/quiz)
|
||||
* [quiz answers](/lessons/lucky-7/quiz-answers)
|
||||
* [challenges](/lessons/lucky-7/challenges)
|
||||
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to display a number, `show number` to generate numbers. We will be learning how to create numbers using show number as well as simple commands, such as pause.
|
||||
|
22
olddocs/lessons/lucky-7/activity.md
Normal file
22
olddocs/lessons/lucky-7/activity.md
Normal file
@ -0,0 +1,22 @@
|
||||
# lucky 7 blocks activity
|
||||
|
||||
Show a number on the LED screen.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Let's learn how to show the lucky number 7 on the LED screen.
|
||||
|
||||
### ~
|
||||
|
||||
We will use `show number` to display a number on the screen. The argument (`7`) is the number to display.
|
||||
|
||||
```blocks
|
||||
basic.showNumber(7)
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/lucky-7/challenges)!
|
||||
|
||||
### ~
|
||||
|
37
olddocs/lessons/lucky-7/challenges.md
Normal file
37
olddocs/lessons/lucky-7/challenges.md
Normal file
@ -0,0 +1,37 @@
|
||||
# lucky 7 blocks challenges
|
||||
|
||||
Coding challenges for lucky 7.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [lucky 7 activity](/lessons/lucky-7/activity) and your code will look like this:
|
||||
|
||||
```blocks
|
||||
basic.showNumber(7)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
But we also should pause before showing another number. Let's add a pause of 500 milliseconds.
|
||||
|
||||
```blocks
|
||||
basic.showNumber(7)
|
||||
basic.pause(500)
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
What about other multiples of 7? Let's display the next multiple of 7 on the screen!
|
||||
|
||||
```blocks
|
||||
basic.showNumber(7)
|
||||
basic.pause(500)
|
||||
basic.showNumber(14)
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Keep displaying multiples of 7 such as 21 and 28...
|
||||
|
35
olddocs/lessons/lucky-7/quiz-answers.md
Normal file
35
olddocs/lessons/lucky-7/quiz-answers.md
Normal file
@ -0,0 +1,35 @@
|
||||
# lucky 7 blocks quiz answers
|
||||
|
||||
Show a number on the micro:bit.
|
||||
|
||||
This is the answer key for the [lucky 7 quiz](/lessons/lucky-7/quiz).
|
||||
|
||||
## 1. Describe what `show number` does?
|
||||
|
||||
Answers may vary. This will show a number on the LED screen, one digit at a time (scrolling from left to right).
|
||||
|
||||
## 2. Draw every LED that is ON after running this code
|
||||
|
||||
```blocks
|
||||
basic.showNumber(7)
|
||||
```
|
||||
|
||||
|
||||

|
||||
|
||||
## 3. Draw every LED that is ON after running this code
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showNumber(21)
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 4. Write the code that will be used to display the number 3 on the micro:bit.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
basic.showNumber(3)
|
||||
```
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user