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

91 lines
1.6 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# screen wipe blocks activity
2016-11-02 01:44:37 +01:00
Clear the screen by pressing buttons on the @boardname@
2016-03-26 00:47:20 +01:00
## ~avatar avatar
2016-03-26 00:47:20 +01:00
2016-05-27 00:24:10 +02:00
2016-03-26 00:47:20 +01:00
2016-11-02 01:44:37 +01:00
This activity will teach how to clear the screen by pressing button A on the @boardname@.
2016-03-26 00:47:20 +01:00
## ~
2016-03-26 00:47:20 +01:00
You can use the 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.
```blocks
basic.showLeds(`
# # # # #
# # # # #
. . . . .
. . . . .
. . . . .
`)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
. . . . .
`)
basic.showLeds(`
. . . . .
. . . . .
# # # # #
# # # # #
. . . . .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
# # # # #
# # # # #
`)
```
We add another line of code that registers an *event handler* `on button pressed` *A* and calls `clear screen`.
```blocks
basic.showLeds(`
# # # # #
# # # # #
. . . . .
. . . . .
. . . . .
`)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
. . . . .
`)
basic.showLeds(`
. . . . .
. . . . .
# # # # #
# # # # #
. . . . .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
# # # # #
# # # # #
`)
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
```
2016-11-02 01:44:37 +01:00
*Run* the script in the simulator or on the @boardname@ to see how this works!
2016-03-26 00:47:20 +01:00
## ~avatar boothing
2016-03-26 00:47:20 +01:00
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
## ~
2016-03-26 00:47:20 +01:00