Migrate docs from the other repo
This commit is contained in:
67
docs/lessons/night-light/activity.md
Normal file
67
docs/lessons/night-light/activity.md
Normal file
@ -0,0 +1,67 @@
|
||||
# night light activity
|
||||
|
||||
Change the brightness of the micro:bit.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/night-light-0
|
||||
|
||||
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](/microbit/lessons/night-light/challenges)!
|
||||
|
||||
### ~
|
||||
|
53
docs/lessons/night-light/challenges.md
Normal file
53
docs/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](/microbit/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
|
||||
|
||||
### @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 `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.
|
Reference in New Issue
Block a user