updated lessons

This commit is contained in:
Michael Elliot Braun
2016-03-30 17:15:42 -07:00
parent d1bf09b084
commit abed962eab
11 changed files with 36 additions and 49 deletions

View File

@ -0,0 +1,83 @@
# bop it challenges
a game similar to "Simon Says" with the BBC micro:bit. #docs
## 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.

View File

@ -0,0 +1,86 @@
# bop it quiz answers
a game where you have to keep up with the commands #math #random #docs
## Name
## Directions
Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial).
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/>
```
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
<br />
```
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
<br />
```
input.onButtonPressed(Button.A, () => {
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
<br />
```
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
<br />
```
input.onLogoDown(() => {
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
<br />
```
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
<br/>
```
input.onLogoDown(() => {
if (action == 1) {
game.addScore(1)
}
})
```

View File

@ -0,0 +1,40 @@
# bop it quiz
a game where you have to keep up with the commands #math #random #docs
## Name
## Directions
Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial).
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 />
<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

View File

@ -0,0 +1,94 @@
# offset image challenges
Coding challenges for the offset image tutorial. #docs
## Before we get started
Complete the following exercise. Your code should look like this:
```blocks
offset = 0
basic.forever(() => {
if (offset == -4) {
basic.showString("Push button A", 150)
}
images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .
`).showImage(offset)
})
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
```
### Challenge 1
Create a condition for if button `B` is pressed. We want the image to move to the left when button `B` is pressed.
```
offset = 0
basic.forever(() => {
if (offset == -4) {
basic.showString("Push button A", 150)
}
images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .
`).showImage(offset)
})
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
input.onButtonPressed(Button.B, () => {
offset = offset - 1 // ***
}) // ***
```
* Run the code to see if it works as expected.
### Challenge 2
### @video td/videos/offset-image-2
Now we want to make sure that the button does not go off the screen to the right. Add a new line that checks to see if offset = 5 after button `A` is pressed.
If `offset = 5` then prompt the user to move the image to the left by displaying the text: "Push button B".
```
offset = 0
basic.forever(() => {
if (offset == -4) {
basic.showString("Push button A", 150)
}
if (offset == 5) {
basic.showString("Press Button B", 150) // ***
}
images.createImage(`
. . # . .
. . # . .
. . # . .
. # # # .
. . # . .
`).showImage(offset)
})
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
input.onButtonPressed(Button.B, () => {
offset = offset - 1
})
```
* Run the code to see if it works as expected.
**Challenge 3**
Now make sure the image does not go off the left side and if it does, prompt the user to push button `A`.

View File

@ -0,0 +1,48 @@
# offset image quiz answers
shift an image horizontally across the display with offset #offset #screen #variables #docs
This is the answer key for the [offset image quiz](/microbit/lessons/offset-image/quiz).
## 1. What is a 'if, then, else statement' ?
<br/>
An if-then statement will run a block of code if the condition specified is true. The statement will run the "else" block of code if that condition is false.
## 2. Consider the message
Write the line of code that that will create the message "Push button A" (Hint: This message appears `if` the offset is equal -4 then the BBC micro:bit will state "Push Button A").
<br/>
```
if (offset == -4) {
basic.showString("Push Button A", 150)
}
```
## 3. Consider the following image
![](/static/mb/lessons/offset-image-0.png)
When with this image be displayed?
<br/>
When the offset is NOT equal to -4 then the BBC micro:bit will show the image above.
## 4. Consider the following image
![](/static/mb/lessons/offset-image-1.png)
Write the two lines of code that cause the `variable` offset to increase by one when button `A` is pressed.
<br/>
```
input.onButtonPressed(Button.A, () => {
offset = offset + 1
})
```

View File

@ -0,0 +1,36 @@
# offset image quiz
shift an image horizontally across the display with offset #offset #screen #variables #docs
## Name
## Directions
Use this activity document to guide your work in the [offset image tutorial](/microbit/lessons/offset-image/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What is an 'if, then, else statement' ?
<br/>
## 2. Write the line condition that if true, will display the message "Push button A". This message appears if the offset is equal -4 then the BBC micro:bit will state "Push Button A".
<br/>
<br/>
## 3. Write the one line of code to show this image
![](/static/mb/lessons/offset-image-0.png)
<br/>
<br/>
## 4. Write the two lines of code that trigger the variable offset to increase by one.
![](/static/mb/lessons/offset-image-1.png)
<br/>

View File

@ -0,0 +1,9 @@
# prank wifi lesson
create a fake wifi app to trick your friends #abs #acceleration #if #math #plot #image #functions #var #docs
create a fake wifi app to trick your friends
* [activity](/microbit/lessons/prank-wifi/activity)
* [quiz](/microbit/lessons/prank-wifi/quiz)

View File

@ -0,0 +1,141 @@
# prank wifi challenges
create a fake wifi app to trick your friends. #docs
## Before we get started
Complete the following exercise. Your code should look like this:
```blocks
basic.showString("Check Wifi", 150)
basic.forever(() => {
let xAccel = math.abs(input.acceleration("x"))
let yAccel = math.abs(input.acceleration("y"))
let zAccel = math.abs(input.acceleration("z"))
let sum = xAccel + yAccel + zAccel
if (sum < 1400) {
basic.showleds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
} else if (sum >= 1400 && sum < 1680) {
basic.showleds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
else if (sum >= 1680) {
basic.showleds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
})
```
**Challenge 1**
What if wanted to show the maximum connectivity of wifi instead of just 1, 3, or 4 bars?
Let's start by changing the first **IF** statement to `if sum <1200`.
Edit this line: if sum is greater than 1400 then just click on the `1400` and backspace until you can add your own number of `1200`.
```blocks
basic.showString("Check Wifi", 150)
basic.forever(() => {
let xAccel1 = math.abs(input.acceleration("x"))
let yAccel1 = math.abs(input.acceleration("y"))
let zAccel1 = math.abs(input.acceleration("z"))
let sum1 = xAccel1 + yAccel1 + zAccel1
if (sum1 < 1200) {
basic.showleds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
} else if (sum1 >= 1400 && sum1 < 1680) {
basic.showleds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
else if (sum1 >= 1680) {
basic.showleds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
})
```
**Challenge 2**
Let's add an **IF** at the bottom of your code that checks to see if `sum >= to 1200` **and** if `sum <1400`
```blocks
basic.showString("Check Wifi", 150)
basic.forever(() => {
let xAccel2 = math.abs(input.acceleration("x"))
let yAccel2 = math.abs(input.acceleration("y"))
let zAccel2 = math.abs(input.acceleration("z"))
let sum2 = xAccel2 + yAccel2 + zAccel2
if (sum2 < 1200) {
basic.showleds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
} else if (sum2 >= 1400 && sum2 < 1680) {
basic.showleds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
else if (sum2 >= 1680) {
basic.showleds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
if (sum2 >= 1200 && sum2 < 1400) {
basic.showleds(`
. . . . #
. . . # #
. . # # #
. # # # #
# # # # #
`) // ***
}
})
```
**Challenge 3**
Now it's your turn! Be creative and change the Wifi meter images to your own wifi image you're sure will prank your friends by editing the lines that call `plot image()`.

View File

@ -0,0 +1,92 @@
# prank wifi quiz answers
create a fake wifi app to trick your friends #string #forever #abs #var #plot #image #if #math #abs #acceleration #docs
## Name
## Directions
Use this activity document to guide your work in the [prank WiFi tutorial](/microbit/lessons/prank-wifi/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the lines of code that takes the absolute value of the accelerations with respect to the x, y and z axis and stores the values as Local Variables
<br/>
```blocks
let xAccel = math.abs(input.acceleration("x"))
let yAccel = math.abs(input.acceleration("y"))
let zAccel = math.abs(input.acceleration("z"))
```
<br/>
## 2. Write the lines of code that add all the accelerations together to get the total acceleration and stores the value as a Local Variable called "sum"
<br/>
<br/>
```blocks
let sum = xAccel + yAccel + zAccel
```
<br/>
## 3. Write the 'If statement' used if the sum of the acceleration value is less than 1400 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi if the acceleration in this 'If statement'
<br/>
```blocks
if (sum < 1400) {
basic.showleds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
}
```
<br/>
## 4. Write tje 'If statement' used if the sum of the acceleration value is greater than 1400 milli-gravitys but less than 1680 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi inside this 'If statement'
<br/>
<br/>
```blocks
if (sum >= 1400 && sum < 1680) {
basic.showleds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
}
```
## 5. Write the 'if statement' needed to display this specific plot image on the device
![](/static/mb/lessons/prank-wifi-0.png)
<br/>
<br/>
```
if (sum >= 1680) {
basic.showleds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
}
```

View File

@ -0,0 +1,46 @@
# prank wifi quiz
create a fake wifi app to trick your friends #string #forever #abs #var #plot #image #if #math #abs #acceleration #docs
## Name
## Directions
Use this activity document to guide your work in the [prank WiFi tutorial](/microbit/lessons/prank-wifi/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the lines of code that takes the absolute value of the accelerations with respect to the x, y and z axis and stores the values as Local Variables
<br/>
<br/>
## 2. Write the lines of code that add all the accelerations together to get the total acceleration and stores the value as a Local Variable called "sum"
<br/>
<br/>
<br/>
## 3. Write the 'If statement' used if the sum of the acceleration value is less than 1400 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi if the acceleration in this 'If statement'
<br/>
<br/>
## 4. Write tje 'If statement' used if the sum of the acceleration value is greater than 1400 milli-gravitys but less than 1680 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi inside this 'If statement'
<br/>
<br/>
## 5. Write the 'if statement' needed to display this specific plot image on the device
![](/static/mb/lessons/prank-wifi-0.png)
<br/>
<br/>