2016-03-26 00:47:20 +01:00
# night light challenges
Coding challenges for night light.
## Before we get started
2016-04-13 17:27:45 +02:00
Complete the following [guided tutorial ](/lessons/night-light/activity ), your code should look like this:
2016-03-26 00:47:20 +01:00
```blocks
led.setBrightness(255)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
```
2017-09-07 22:42:08 +02:00
## Challenge 1
2016-03-26 00:47:20 +01:00
2016-05-27 00:24:10 +02:00
2016-03-26 00:47:20 +01:00
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)
})
```
2018-10-22 19:00:57 +02:00
## Challenge 2
2016-03-26 00:47:20 +01:00
Add an event handler with `on shake` to change the LED brightness back to a `255` .