move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
65
olddocs/lessons/night-light/activity.md
Normal file
65
olddocs/lessons/night-light/activity.md
Normal file
@ -0,0 +1,65 @@
|
||||
# night light activity
|
||||
|
||||
Change the brightness of the micro:bit.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will teach you how to change the brightness of the micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
The brightness of the LED screen can be changed by using the `set brightness` function. This function takes a number between ``0`` (off) and ``255`` (full brightness).
|
||||
|
||||
Let's build a little app that dims the screen when pressing button ``A``.
|
||||
|
||||
Add the code `show LEDs` and select all LEDs to turn on all the LEDs. Don't hesitate to run your code to see what happens.
|
||||
|
||||
```blocks
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
The screen starts with a 50% brightness value by default (128). Add a new line of code to set the full brightness (255) using `set brightness`.
|
||||
|
||||
```blocks
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
Add a new event handler for `on button pressed(A)` and add the code to set the brightness to `64`.
|
||||
|
||||
|
||||
```blocks
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/night-light/challenges)!
|
||||
|
||||
### ~
|
||||
|
53
olddocs/lessons/night-light/challenges.md
Normal file
53
olddocs/lessons/night-light/challenges.md
Normal file
@ -0,0 +1,53 @@
|
||||
# night light challenges
|
||||
|
||||
Coding challenges for night light.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/night-light/activity), your code should look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
|
||||
```
|
||||
### Challenge 1
|
||||
|
||||
|
||||
|
||||
What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add an event handler with `on button pressed(B)` add `set brightness(0)` to turn off the LEDs.
|
||||
|
||||
|
||||
```blocks
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
led.setBrightness(0)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add an event handler with `on shake` to change the LED brightness back to a `255`.
|
||||
|
||||
* `Run main` your script to see the LEDs change brightness.
|
94
olddocs/lessons/night-light/offset-image/activity.md
Normal file
94
olddocs/lessons/night-light/offset-image/activity.md
Normal file
@ -0,0 +1,94 @@
|
||||
# offset image challenges
|
||||
|
||||
Coding challenges for the offset image tutorial.
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
|
||||
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`.
|
||||
|
48
olddocs/lessons/night-light/offset-image/quiz-answers.md
Normal file
48
olddocs/lessons/night-light/offset-image/quiz-answers.md
Normal file
@ -0,0 +1,48 @@
|
||||
# offset image quiz answers
|
||||
|
||||
shift an image horizontally across the display with offset.
|
||||
|
||||
This is the answer key for the [offset image quiz](/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
|
||||
|
||||

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

|
||||
|
||||
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
|
||||
})
|
||||
```
|
||||
|
36
olddocs/lessons/night-light/offset-image/quiz.md
Normal file
36
olddocs/lessons/night-light/offset-image/quiz.md
Normal file
@ -0,0 +1,36 @@
|
||||
# offset image quiz
|
||||
|
||||
shift an image horizontally across the display with offset.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [offset image activity](/lessons/offset-image/activity).
|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the two lines of code that trigger the variable offset to increase by one.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
58
olddocs/lessons/night-light/quiz-answers.md
Normal file
58
olddocs/lessons/night-light/quiz-answers.md
Normal file
@ -0,0 +1,58 @@
|
||||
# night light quiz answers
|
||||
|
||||
Answers to the night light quiz.
|
||||
|
||||
This is the answer key for the [night light quiz](/lessons/night-light/quiz).
|
||||
|
||||
## 1. Define the function "set brightness"
|
||||
|
||||
This function sets the brightness of the LED screen.
|
||||
|
||||
## 2. Consider the following image
|
||||
|
||||

|
||||
|
||||
If the rectangle above represents the BBC micro:bit, write the code to set all the LEDs to full brightness and to turn on all the LEDs.
|
||||
|
||||
<br />
|
||||
|
||||
```blocks
|
||||
led.setBrightness(255)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
## 3. Consider the following image
|
||||
|
||||

|
||||
|
||||
If the rectangle above represents the BBC micro:bit, write the code to set the screen brightness to 50% (128) and turns on all the LEDs.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
led.setBrightness(128)
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
`)
|
||||
```
|
||||
|
||||
## 4. Consider the following image
|
||||
|
||||

|
||||
|
||||
If the rectangle above represents the BBC micro:bit, write the code to turn off all the LEDs.
|
||||
|
||||
```blocks
|
||||
led.setBrightness(0)
|
||||
```
|
||||
|
30
olddocs/lessons/night-light/quiz.md
Normal file
30
olddocs/lessons/night-light/quiz.md
Normal file
@ -0,0 +1,30 @@
|
||||
# night light quiz
|
||||
|
||||
change the brightness of the BBC micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [night light tutorial](/lessons/night-light/activity)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "led->set brightness" does ?
|
||||
|
||||
## 2. If the picture below is the BBC micro:bit, write the code that sets all the LEDs to full brightness and turns on all the LEDs
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
## 3. If the picture below is the BBC micro:bit, write the code that sets the screen brightness to 50% (128) and turns on all the LEDs.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 4. If the picture below is the BBC micro:bit, write the code turns off all the LEDs.
|
||||
|
||||

|
||||
|
Reference in New Issue
Block a user