Migrate docs from the other repo
This commit is contained in:
45
docs/reference/js/lessons/night-light/activity.md
Normal file
45
docs/reference/js/lessons/night-light/activity.md
Normal file
@ -0,0 +1,45 @@
|
||||
# night light activity
|
||||
|
||||
change the brightness of the BBC micro:bit. #docs #tutorials #stepByStep
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/night-light-0
|
||||
|
||||
Welcome! This tutorial will teach you how to change the brightness of the BBC micro:bit. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
The brightness of the LED screen can be changed by using the `led->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 `led->plot all` to turn on all the LEDs. Don't hesitate to run your code to see what happens.
|
||||
|
||||
```
|
||||
led.plotAll() // ***
|
||||
```
|
||||
|
||||
The screen starts with a 50% brightness value by default (128). Add a new line of code to set the full brightness (255) using `led->set brightness`.
|
||||
|
||||
```
|
||||
led.setBrightness(255) // ***
|
||||
led.plotAll()
|
||||
```
|
||||
|
||||
Add a new event handler for `input->on button pressed(A)` and add the code to set the brightness to `64`.
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed("A", () => {
|
||||
led.setBrightness(64) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/night-light/challenges)!
|
||||
|
||||
### ~
|
||||
|
42
docs/reference/js/lessons/night-light/challenges.md
Normal file
42
docs/reference/js/lessons/night-light/challenges.md
Normal file
@ -0,0 +1,42 @@
|
||||
# night light challenges
|
||||
|
||||
Coding challenges for the night light tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/night-light/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed("A", () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/night-light-2
|
||||
|
||||
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 `input->on button pressed(B)` add `led->set brightness(0)` to turn off the LEDs.
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed("A", () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
led.setBrightness(0) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Add an event handler with `input->on screen up` to change the LED brightness back to a `255`.
|
||||
|
||||
* `Run main` your script to see the LEDs change brightness.
|
46
docs/reference/js/lessons/night-light/quiz-answers.md
Normal file
46
docs/reference/js/lessons/night-light/quiz-answers.md
Normal file
@ -0,0 +1,46 @@
|
||||
# night light quiz answers
|
||||
|
||||
Answers to the night light quiz. #LED #image #brightness #fade #docs
|
||||
|
||||
This is the answer key for the [night light quiz](/microbit/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 />
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
```
|
||||
|
||||
## 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/>
|
||||
|
||||
```
|
||||
led.setBrightness(128)
|
||||
led.plotAll()
|
||||
```
|
||||
|
||||
## 4. Consider the following image
|
||||
|
||||

|
||||
|
||||
If the rectangle above represents the BBC micro:bit, write the code to turn off all the LEDs.
|
||||
|
||||
```
|
||||
led.setBrightness(0)
|
||||
```
|
||||
|
30
docs/reference/js/lessons/night-light/quiz.md
Normal file
30
docs/reference/js/lessons/night-light/quiz.md
Normal file
@ -0,0 +1,30 @@
|
||||
# night light quiz
|
||||
|
||||
change the brightness of the BBC micro:bit #LED #image #brightness #fade #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [night light tutorial](/microbit/lessons/night-light/tutorial)
|
||||
|
||||
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