pxt-calliope/docs/reference/js/lessons/night-light/challenges.md

43 lines
1.0 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# night light challenges
Coding challenges for the night light tutorial. #docs
## Before we get started
Complete the following guided tutorial:
2016-04-13 17:27:45 +02:00
* [tutorial](/lessons/night-light/tutorial)
2016-03-26 00:47:20 +01:00
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
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(Button.A, () => {
2016-03-26 00:47:20 +01:00
led.setBrightness(64)
})
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
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.