Migrate docs from the other repo
This commit is contained in:
63
docs/reference/js/lessons/flashing-heart/activity.md
Normal file
63
docs/reference/js/lessons/flashing-heart/activity.md
Normal file
@ -0,0 +1,63 @@
|
||||
# flashing heart activity
|
||||
|
||||
Ccontrol images with variables.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/flashing-heart-0
|
||||
|
||||
In this activity, you will learn how to blink an image on the LED screen.
|
||||
|
||||
### ~
|
||||
|
||||
To create a new script, go to the [Create Code](https://www.microbit.co.uk/create-code) page and tap `New Project` under **KindScript**.
|
||||
|
||||
Let's start by adding code that plots a heart image on the screen using `basic->plot image`. Once you are done coding, don't forget to run your code in the simulator or the BBC micro:bit.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`) // ***
|
||||
```
|
||||
|
||||
We want to leave the image on the screen for 0.5 seconds (500 milliseconds), then clear the screen. We can use `basic->pause` to wait and `basic->clear screen` to turn off the LEDs.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500) // ***
|
||||
basic.clearScreen() // ***
|
||||
```
|
||||
|
||||
Finally, we can surround this code with a `basic->forever` loop to repeat it and add a pause after `basic->clear screen` to keep the screen off for a little while. Modify your code so that your code looks like this.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/flashing-heart/challenges)!
|
||||
|
||||
### ~
|
||||
|
Reference in New Issue
Block a user