updated lessons
This commit is contained in:
parent
f00491df52
commit
1e77491b16
@ -10,15 +10,10 @@ Variables
|
|||||||
|
|
||||||
## Quick Links
|
## Quick Links
|
||||||
|
|
||||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
|
||||||
* [quiz](/microbit/lessons/catch-the-egg-game/quiz)
|
* [quiz](/microbit/lessons/catch-the-egg-game/quiz)
|
||||||
* [quiz answers](/microbit/lessons/catch-the-egg-game/quiz-answers)
|
* [quiz answers](/microbit/lessons/catch-the-egg-game/quiz-answers)
|
||||||
* [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
* [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
||||||
|
|
||||||
## Class
|
|
||||||
|
|
||||||
Year 7
|
|
||||||
|
|
||||||
## Prior learning/place of lesson in scheme of work
|
## 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.
|
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.
|
||||||
@ -52,40 +47,3 @@ Learn how to create a catch the egg game game with **plot**, `led->plot` , **unp
|
|||||||
* learn how to return the modulus
|
* learn how to return the modulus
|
||||||
* learn how to show a number of the BBC micro:bit screen
|
* learn how to show a number of the BBC micro:bit screen
|
||||||
* learn how to pause your code for the specified number of milliseconds
|
* learn how to pause your code for the specified number of milliseconds
|
||||||
|
|
||||||
## 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
|
|
||||||
|
|
||||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
|
||||||
|
|
||||||
## Activity
|
|
||||||
|
|
||||||
* time: 20 min.
|
|
||||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
|
||||||
* [quiz](/microbit/lessons/catch-the-egg-game/quiz)
|
|
||||||
|
|
||||||
## Extended Activity
|
|
||||||
|
|
||||||
* time: 20 min.
|
|
||||||
* [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
|
||||||
|
|
||||||
## Homework
|
|
||||||
|
|
||||||
* Extended Activity: [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
|
||||||
|
|
@ -4,13 +4,9 @@ Coding challenges for catch the egg game.
|
|||||||
|
|
||||||
## Before we get started
|
## Before we get started
|
||||||
|
|
||||||
Complete the following guided tutorial:
|
Your starting code should look like this:
|
||||||
|
|
||||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
```blocks
|
||||||
|
|
||||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
|
||||||
|
|
||||||
```
|
|
||||||
let basketX = 2
|
let basketX = 2
|
||||||
let eggX = 2
|
let eggX = 2
|
||||||
let eggY = 0
|
let eggY = 0
|
||||||
@ -20,7 +16,7 @@ basic.forever(() => {
|
|||||||
eggY = eggY + 1
|
eggY = eggY + 1
|
||||||
led.plot(eggX, eggY)
|
led.plot(eggX, eggY)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX = input.acceleration("x")
|
let accX = input.acceleration(Dimension.X)
|
||||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||||
led.plot(basketX, 4)
|
led.plot(basketX, 4)
|
||||||
if (eggY > 4) {
|
if (eggY > 4) {
|
||||||
@ -49,7 +45,7 @@ Now that we know when an egg is caught, we can keep track of the score! We need
|
|||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let basketX1 = 2
|
let basketX1 = 2
|
||||||
let eggX1 = 2
|
let eggX1 = 2
|
||||||
let eggY1 = 0
|
let eggY1 = 0
|
||||||
@ -59,8 +55,8 @@ basic.forever(() => {
|
|||||||
eggY1 = eggY1 + 1
|
eggY1 = eggY1 + 1
|
||||||
led.plot(eggX1, eggY1)
|
led.plot(eggX1, eggY1)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX1 = input.acceleration("x")
|
let accX = input.acceleration(Dimension.X)
|
||||||
basketX1 = 2 + Math.min(2, Math.max(-2, accX1 / 200))
|
basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||||
led.plot(basketX1, 4)
|
led.plot(basketX1, 4)
|
||||||
if (eggY1 > 4) {
|
if (eggY1 > 4) {
|
||||||
eggY1 = -1
|
eggY1 = -1
|
||||||
@ -87,7 +83,7 @@ Catching eggs gets easier with practice so let's make the eggs fall faster every
|
|||||||
|
|
||||||
### ~
|
### ~
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let basketX2 = 2
|
let basketX2 = 2
|
||||||
let eggX2 = 2
|
let eggX2 = 2
|
||||||
let eggY2 = 0
|
let eggY2 = 0
|
||||||
@ -98,7 +94,7 @@ basic.forever(() => {
|
|||||||
eggY2 = eggY2 + 1
|
eggY2 = eggY2 + 1
|
||||||
led.plot(eggX2, eggY2)
|
led.plot(eggX2, eggY2)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX2 = input.acceleration("x")
|
let accX2 = input.acceleration(Dimension.X)
|
||||||
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
|
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
|
||||||
led.plot(basketX2, 4)
|
led.plot(basketX2, 4)
|
||||||
if (eggY2 > 4) {
|
if (eggY2 > 4) {
|
||||||
@ -108,7 +104,7 @@ basic.forever(() => {
|
|||||||
if (eggY2 == 4) {
|
if (eggY2 == 4) {
|
||||||
if (basketX2 == eggX2) {
|
if (basketX2 == eggX2) {
|
||||||
game.addScore(1)
|
game.addScore(1)
|
||||||
if (math.mod(game.score(), 5) == 0) {
|
if (game.score() %5 == 0) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
game.removeLife(1)
|
game.removeLife(1)
|
||||||
@ -126,7 +122,7 @@ basic.forever(() => {
|
|||||||
|
|
||||||
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**.
|
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 basketX3 = 2
|
||||||
let eggX3 = 2
|
let eggX3 = 2
|
||||||
let eggY3 = 0
|
let eggY3 = 0
|
||||||
@ -137,7 +133,7 @@ basic.forever(() => {
|
|||||||
eggY3 = eggY3 + 1
|
eggY3 = eggY3 + 1
|
||||||
led.plot(eggX3, eggY3)
|
led.plot(eggX3, eggY3)
|
||||||
basic.pause(300)
|
basic.pause(300)
|
||||||
let accX3 = input.acceleration("x")
|
let accX3 = input.acceleration(Dimension.X)
|
||||||
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
|
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
|
||||||
led.plot(basketX3, 4)
|
led.plot(basketX3, 4)
|
||||||
if (eggY3 > 4) {
|
if (eggY3 > 4) {
|
||||||
@ -147,7 +143,7 @@ basic.forever(() => {
|
|||||||
if (eggY3 == 4) {
|
if (eggY3 == 4) {
|
||||||
if (basketX3 == eggX3) {
|
if (basketX3 == eggX3) {
|
||||||
game.addScore(1)
|
game.addScore(1)
|
||||||
if (math.mod(game.score(), 5) == 0) {
|
if (game.score()% 5 == 0) {
|
||||||
fallingPause1 = fallingPause1 - 25 // ***
|
fallingPause1 = fallingPause1 - 25 // ***
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -156,6 +152,7 @@ basic.forever(() => {
|
|||||||
}
|
}
|
||||||
basic.pause(fallingPause1) // ***
|
basic.pause(fallingPause1) // ***
|
||||||
})
|
})
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Fantastic! Your game is now ready to show off.
|
Fantastic! Your game is now ready to show off.
|
@ -22,7 +22,10 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
|
let basketX = 2
|
||||||
|
let eggX = 2
|
||||||
|
let eggY = 0
|
||||||
led.plot(eggX, eggY)
|
led.plot(eggX, eggY)
|
||||||
led.plot(basketX, 4)
|
led.plot(basketX, 4)
|
||||||
```
|
```
|
||||||
@ -31,28 +34,22 @@ led.plot(basketX, 4)
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
|
let basketX = 2
|
||||||
|
let eggX = 2
|
||||||
|
let eggY = 0
|
||||||
led.unplot(eggX, eggY)
|
led.unplot(eggX, eggY)
|
||||||
eggY = eggY + 1
|
eggY = eggY + 1
|
||||||
led.plot(eggX, eggY)
|
led.plot(eggX, eggY)
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4. Write the code that calculates 'basket x' given the variable 'acc x'.
|
## 4. . Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let accX = input.acceleration("x")
|
let eggX = 2
|
||||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
let eggY = 0
|
||||||
```
|
|
||||||
|
|
||||||
Note: the first line of code in this answer is optional.
|
|
||||||
|
|
||||||
## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
```
|
|
||||||
if (eggY > 4) {
|
if (eggY > 4) {
|
||||||
eggY = -1
|
eggY = -1
|
||||||
eggX = Math.random(5)
|
eggX = Math.random(5)
|
@ -24,11 +24,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
## 4. Write the code that calculates 'basket x' given the variable 'acc x'.
|
## 4. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||||
|
|
||||||
<br/>
|
|
||||||
|
|
||||||
## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
@ -26,6 +26,7 @@ let degrees = input.compassHeading()
|
|||||||
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
let degrees = input.compassHeading()
|
||||||
if (degrees < 45) {
|
if (degrees < 45) {
|
||||||
basic.showString("N", 150)
|
basic.showString("N", 150)
|
||||||
}
|
}
|
||||||
@ -35,6 +36,7 @@ if (degrees < 45) {
|
|||||||
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
let degrees = input.compassHeading()
|
||||||
if (degrees < 135) {
|
if (degrees < 135) {
|
||||||
basic.showString("E", 150)
|
basic.showString("E", 150)
|
||||||
}
|
}
|
||||||
@ -44,6 +46,7 @@ if (degrees < 135) {
|
|||||||
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
|
let degrees = input.compassHeading()
|
||||||
if (degrees < 225) {
|
if (degrees < 225) {
|
||||||
basic.showString("S", 150)
|
basic.showString("S", 150)
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ We create a **variable**, `count` to keep track of the current count. The number
|
|||||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let count_ = 0
|
let counts = 0
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
count_ = count_ + 1
|
counts = counts + 1
|
||||||
basic.showNumber(count, 150)
|
basic.showNumber(counts, 150)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ We are only pressing on button pressed once. So the number to display on the mic
|
|||||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
count_ = 0
|
let counting= 0
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
count_ = count_ + 1
|
counting = counting + 1
|
||||||
basic.showNumber(count_, 100)
|
basic.showNumber(counting, 100)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ let count = 0
|
|||||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
let count_ = 0
|
let counts = 0
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
count_ = count_ + 1
|
counts = counts + 1
|
||||||
basic.showNumber(count_, 100)
|
basic.showNumber(counts, 150)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -41,10 +41,10 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
count_ = 0
|
let counting= 0
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
count_ = count_ + 1
|
counting = counting + 1
|
||||||
basic.showNumber(count_, 100)
|
basic.showNumber(counting, 100)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ A loop that repeats code while a condition is true.
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let count = 0
|
let count = 0
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -26,7 +26,8 @@ let count = 0
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
|
let count = 0
|
||||||
while (count < 5) {
|
while (count < 5) {
|
||||||
count = count + 1
|
count = count + 1
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ When the micro:bit goes logo up, the code nested under the `on logo up` function
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onLogoUp(() => {
|
input.onLogoUp(() => {
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . # . .
|
. . # . .
|
||||||
. # # # .
|
. # # # .
|
||||||
# # # # #
|
# # # # #
|
||||||
@ -31,6 +31,7 @@ input.onLogoUp(() => {
|
|||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Run your code and try to turn around the micro:bit to see the **logo up** event in action!
|
Run your code and try to turn around the micro:bit to see the **logo up** event in action!
|
||||||
|
@ -8,7 +8,7 @@ Complete the [magic logo](/microbit/lessons/magic-logo/activity) activity and yo
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onLogoUp(() => {
|
input.onLogoUp(() => {
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . # . .
|
. . # . .
|
||||||
. # # # .
|
. # # # .
|
||||||
# # # # #
|
# # # # #
|
||||||
@ -28,7 +28,7 @@ How about when the logo is down? We should display an arrow pointing downward!
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onLogoUp(() => {
|
input.onLogoUp(() => {
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . # . .
|
. . # . .
|
||||||
. # # # .
|
. # # # .
|
||||||
# # # # #
|
# # # # #
|
||||||
@ -37,7 +37,7 @@ input.onLogoUp(() => {
|
|||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
input.onLogoDown(() => {
|
input.onLogoDown(() => {
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . # . .
|
. . # . .
|
||||||
. . # . .
|
. . # . .
|
||||||
# # # # #
|
# # # # #
|
||||||
|
@ -44,7 +44,7 @@ input.onLogoUp(() => {
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
input.onLogoDown(() => {
|
input.onLogoDown(() => {
|
||||||
basic.plotImage(`
|
basic.showLeds(`
|
||||||
. . # . .
|
. . # . .
|
||||||
. . # . .
|
. . # . .
|
||||||
# # # # #
|
# # # # #
|
||||||
|
@ -4,34 +4,50 @@ Learn how to create a rotating image with a while loop. #image #loop #while #do
|
|||||||
|
|
||||||
This is the answer key for the [rotation animation quiz](/microbit/lessons/rotation-animation/quiz).
|
This is the answer key for the [rotation animation quiz](/microbit/lessons/rotation-animation/quiz).
|
||||||
|
|
||||||
## 1. What is a "global variable"?
|
## 1. What is a " variable"?
|
||||||
|
|
||||||
Answers may vary. A global variable is a place where you can store data so that you can use it later in your code.
|
Answers may vary. A variable is a place where you can store data so that you can use it later in your code.
|
||||||
|
|
||||||
## 2. Consider the following directions
|
## 2. Write the code to create a ** variable** called `foo` that stores a boolean and initialize it to **false**.
|
||||||
|
|
||||||
Write the code to create a **global variable** called `foo` that stores a boolean and initialize it to **false**.
|
|
||||||
|
|
||||||
```
|
|
||||||
rotating = true
|
```blocks
|
||||||
|
let rotating = true;
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. Consider the following code
|
## 3. Explain what this line of code does.
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
|
let rotating = true;
|
||||||
while (rotating) {
|
while (rotating) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Explain what this line of code does.
|
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
It is a **while** loop that will be executed only if the **global variable** called `rotating` is **true**.
|
It is a **while** loop that will be executed only if the ** variable** called `rotating` is **true**.
|
||||||
|
|
||||||
## 4. Consider the following code
|
## 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
|
||||||
basic.showAnimation(`
|
basic.showAnimation(`
|
||||||
# . . . . . . # . . . . . . # . . . . .
|
# . . . . . . # . . . . . . # . . . . .
|
||||||
. # . . . . . # . . . . . # . . . . . .
|
. # . . . . . # . . . . . # . . . . . .
|
||||||
@ -41,7 +57,7 @@ basic.showAnimation(`
|
|||||||
`, 400)
|
`, 400)
|
||||||
```
|
```
|
||||||
|
|
||||||
If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded.
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -10,26 +10,42 @@ Use this activity document to guide your work in the [rotation animation tutoria
|
|||||||
|
|
||||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||||
|
|
||||||
## 1. What is a "global variable"?
|
## 1. What is a " variable"?
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
## 2. Write the code to create a global variable called foo that stores a boolean and initialize it to false.
|
## 2. Write the code to create a variable called foo that stores a boolean and initialize it to false.
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
## 3. Explain why you use a while loop with a global variable
|
## 3. Explain why you use a while loop with a variable
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
|
let rotating = true;
|
||||||
while (rotating) {
|
while (rotating) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
## 4. Draw the areas on the micro:bits to illustrate the code below. Explain why you chose to draw in those areas.
|
## 4. Draw the areas on the micro:bits to illustrate the code below. Explain why you chose to draw in those areas.
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
basic.showAnimation(`
|
basic.showAnimation(`
|
||||||
# . . . . . . # . . . . . . # . . . . .
|
# . . . . . . # . . . . . . # . . . . .
|
||||||
. # . . . . . # . . . . . # . . . . . .
|
. # . . . . . # . . . . . # . . . . . .
|
||||||
|
@ -13,14 +13,14 @@ Welcome! This tutorial will help you make a smiley face blink. Let's get started
|
|||||||
Create an animation with an image displaying a smiley face and the next image with no LEDs lit up. This will make it look like the smiley face is blinking as the display switches between images.
|
Create an animation with an image displaying a smiley face and the next image with no LEDs lit up. This will make it look like the smiley face is blinking as the display switches between images.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. # . # .
|
. # . # .
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
. . . . .
|
||||||
# . . . #
|
# . . . #
|
||||||
. # # # .
|
. # # # .
|
||||||
`)
|
`)
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
|
@ -8,14 +8,14 @@ Complete the [smiley activity](/microbit/lessons/smiley/activity) and your code
|
|||||||
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. # . # .
|
. # . # .
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
. . . . .
|
||||||
# . . . #
|
# . . . #
|
||||||
. # # # .
|
. # # # .
|
||||||
`)
|
`)
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
@ -33,14 +33,14 @@ Let's make add code that will run when button A is pressed!
|
|||||||
|
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. # . # .
|
. # . # .
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
. . . . .
|
||||||
# . . . #
|
# . . . #
|
||||||
. # # # .
|
. # # # .
|
||||||
`)
|
`)
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
@ -59,14 +59,14 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
Now, we want to show a frowny face when this button is pressed. Let's show the LEDs.
|
Now, we want to show a frowny face when this button is pressed. Let's show the LEDs.
|
||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. # . # .
|
. # . # .
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
. . . . .
|
||||||
# . . . #
|
# . . . #
|
||||||
. # # # .
|
. # # # .
|
||||||
`)
|
`)
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
. . . . .
|
. . . . .
|
||||||
@ -74,7 +74,7 @@ basic.showAnimation(`
|
|||||||
. . . . .
|
. . . . .
|
||||||
`)
|
`)
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
basic.showAnimation(`
|
basic.showLeds(`
|
||||||
. # . # .
|
. # . # .
|
||||||
. # . # .
|
. # . # .
|
||||||
. . . . .
|
. . . . .
|
||||||
|
@ -51,7 +51,7 @@ basic.forever(() => {
|
|||||||
. . # . .
|
. . # . .
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
```blocks
|
```
|
||||||
|
|
||||||
Run your code in the simulator or download it to your BBC micro:bit to see what happens!
|
Run your code in the simulator or download it to your BBC micro:bit to see what happens!
|
||||||
|
|
||||||
|
@ -6,25 +6,59 @@ Coding challenges for snowflake fall.
|
|||||||
|
|
||||||
Complete the [snowflake fall](/microbit/lessons/snowflake-fall/activity) activity and your code will look like this:
|
Complete the [snowflake fall](/microbit/lessons/snowflake-fall/activity) activity and your code will look like this:
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # . # .
|
||||||
|
# . . . #
|
||||||
|
. # . # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### Challenge 1
|
### Challenge 1
|
||||||
|
|
||||||
### @video td/videos/snowflake-fall-1
|
### @video td/videos/snowflake-fall-1
|
||||||
|
|
||||||
Let's begin creating our falling effect by adding another snowflake with `show LEDs` that displays a different snowflake pattern after the first one. We need 2 frames in the new animation that display both the first and the second snowflake images.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* Run your program to see the cool animation.
|
|
||||||
|
|
||||||
### Challenge 2
|
|
||||||
|
|
||||||
### @video td/videos/snowflake-fall-2
|
|
||||||
|
|
||||||
To finalize our snowflake fall, let's add a different snowflake pattern.
|
To finalize our snowflake fall, let's add a different snowflake pattern.
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # . # .
|
||||||
|
# . . . #
|
||||||
|
. # . # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
basic.showLeds(`
|
||||||
|
. # . # .
|
||||||
|
# # # # #
|
||||||
|
. # . # .
|
||||||
|
# # # # #
|
||||||
|
. # . # .
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
* Run your program and see if it works.
|
* Run your program and see if it works.
|
||||||
|
|
||||||
|
@ -28,7 +28,24 @@ basic.forever(() => {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
`);
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
. . . . .
|
||||||
|
`)
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## 4. Write the code for a forever loop and show LEDS for these images!
|
## 4. Write the code for a forever loop and show LEDS for these images!
|
||||||
|
|
||||||
@ -36,5 +53,21 @@ basic.forever(() => {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||

|
```blocks
|
||||||
|
basic.forever(() => {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . . . .
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
. . . . .
|
||||||
|
`);
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# # . # #
|
||||||
|
# . # . #
|
||||||
|
# # . # #
|
||||||
|
# # # # #
|
||||||
|
`)
|
||||||
|
});
|
||||||
|
```
|
@ -12,19 +12,95 @@ Welcome! This guided tutorial will teach how to program a script that randomly p
|
|||||||
|
|
||||||
Let's begin by adding an `on shake` condition to know when the micro:bit is shaken.
|
Let's begin by adding an `on shake` condition to know when the micro:bit is shaken.
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction.
|
Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction.
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(4)
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0.
|
Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0.
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(4)
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 2) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
# # # # #
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Now let's handle the rest of the cases for `random arrow`.
|
Now let's handle the rest of the cases for `random arrow`.
|
||||||
|
|
||||||

|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(4)
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 2) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
# # # # #
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # . .
|
||||||
|
# # # # #
|
||||||
|
. # # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### ~avatar avatar
|
### ~avatar avatar
|
||||||
|
|
||||||
|
@ -6,21 +6,164 @@ Create an arrow that randomly points to a player.
|
|||||||
|
|
||||||
Complete the following [guided tutorial](/microbit/lessons/spinner/activity), your code should look like this:
|
Complete the following [guided tutorial](/microbit/lessons/spinner/activity), your code should look like this:
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(4)
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 2) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
# # # # #
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # . .
|
||||||
|
# # # # #
|
||||||
|
. # # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### Challenge 1
|
### Challenge 1
|
||||||
|
|
||||||
Modify the random number generator so that it can include new arrows we will create in the next challenge.
|
Modify the random number generator so that it can include new arrows we will create in the next challenge.
|
||||||
|
|
||||||

|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(8)
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 2) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
# # # # #
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # . .
|
||||||
|
# # # # #
|
||||||
|
. # # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
* Do **not** run the code yet because it will not work until you have conditions for every random number.
|
* Do **not** run the code yet because it will not work until you have conditions for every random number.
|
||||||
|
|
||||||
### Challenge 2
|
### Challenge 2
|
||||||
|
|
||||||
Let's add four more arrows that point diagonally.
|
Let's add more arrows that point diagonally.
|
||||||
|
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
input.onGesture(Gesture.Shake, () => {
|
||||||
|
let randomArrow = Math.random(8)
|
||||||
|
if (randomArrow = 7) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # # .
|
||||||
|
# # # # #
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 6) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . # . .
|
||||||
|
# # # # #
|
||||||
|
. # # # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
if (randomArrow = 5) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. # # . .
|
||||||
|
# # # # #
|
||||||
|
. # # . .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
if (randomArrow = 4) {
|
||||||
|
basic.showLeds(`
|
||||||
|
. . # . .
|
||||||
|
. . . # .
|
||||||
|
# # # # #
|
||||||
|
. . . # .
|
||||||
|
. . # . .
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (randomArrow = 3) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# # # # .
|
||||||
|
# # # # .
|
||||||
|
# . . # .
|
||||||
|
. . . . #
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
if (randomArrow = 2) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# # # # #
|
||||||
|
# # # # #
|
||||||
|
. . # # #
|
||||||
|
. # . # #
|
||||||
|
# . . . #
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
if (randomArrow = 1) {
|
||||||
|
basic.showLeds(`
|
||||||
|
# . . . #
|
||||||
|
# # . # .
|
||||||
|
# # # . .
|
||||||
|
# # # # .
|
||||||
|
# # # # #
|
||||||
|
`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* Run your code to see if it works as expected
|
* Run your code to see if it works as expected
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ Write the line of code to measure the acceleration and then store in it a variab
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let accX_ = input.acceleration("x")
|
let accX_ = input.acceleration("x")
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ After storing the acceleration in a variable, write the code to show acceleratio
|
|||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
```
|
```blocks
|
||||||
let accX = input.acceleration("x")
|
let accX = input.acceleration("x")
|
||||||
basic.showNumber(accX_, 150)
|
basic.showNumber(accX, 150)
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: make sure the same variable name ("acc x" in this case) is the same in both lines of code..
|
Note: make sure the same variable name ("acc x" in this case) is the same in both lines of code..
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
# catch the egg
|
|
||||||
|
|
||||||
Programming a game of 'catch the egg' using the accelerometer in Touch Develop #docs #functions #var
|
|
||||||
|
|
||||||
Programming a game of 'catch the egg' using the accelerometer
|
|
||||||
|
|
||||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
|
||||||
* [challenges](/microbit/lessons/catch-the-egg/challenges)
|
|
Loading…
x
Reference in New Issue
Block a user