pxt-calliope/docs/reference/js/lessons/screen-wipe/activity.md

48 lines
1.4 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# screen wipe activity
2016-04-02 01:22:47 +02:00
Clear the screen by pressing buttons on the BBC micro:bit.
2016-03-26 00:47:20 +01:00
### ~avatar avatar
### @video td/videos/screen-wipe-0
This activity will teach how to clear the screen by pressing button ``A`` on the BBC micro:bit.
### ~
You can use the `basic->clear screen` function to turn off all the LED on the screen. Let's illustrate this concept with a small script where the user has to press the button ``A`` to turn off the screen. Let's start by adding the code to show an animation.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400) // ***
```
We add another line of code that registers an **event handler** on the `input->on button pressed(A)` and calls `basic->clear screen`.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
basic.clearScreen() // ***
}) // ***
```
Run the script in the simulator or on the BBC micro:bit to see how this works!
### ~avatar boothing
2016-04-13 17:27:45 +02:00
Excellent, you're ready to continue with the [challenges](/lessons/screen-wipe/challenges)!
2016-03-26 00:47:20 +01:00
### ~