pxt-calliope/docs/lessons/flashing-heart/challenges.md
2016-03-25 16:47:20 -07:00

2.0 KiB

flashing heart blocks challenges

Coding challenges for the flashing heart tutorial.

Before we get started

Complete the flashing heart activity and your code will look like this:

basic.forever(() => {
    basic.showLeds(`
        . # . # .
        # # # # #
        # # # # #
        . # # # .
        . . # . .
        `)
    basic.pause(500)
    basic.clearScreen()
    basic.pause(500)

})

Challenge 1

@video td/videos/flashing-heart-1

Let's plot a different image. Let's display a broken heart!

To do this, you need to add a block between the last line and the end loop. Add a show LEDs block and then add a pause of 500 milliseconds.

basic.forever(() => {
    basic.showLeds(`
        . # . # .
        # # # # #
        # # # # #
        . # # # .
        . . # . .
        `)
    basic.pause(500)
    basic.clearScreen()
    basic.pause(500)
    basic.showLeds(`
        . # . # .
        # . # # #
        # . . # #
        . # # # .
        . . # . .
        `)
    basic.pause(500)
})
  • click run main to see if the code works as expected.

Challenge 2

@video td/videos/flashing-heart-2

Now let's alternate flashing the heart and the broken heart. To do this, we need to add a clear screen block and then add a pause block of 500 milliseconds under the new code we added in Challenge 1.

basic.forever(() => {
    basic.showLeds(`
        . # . # .
        # . # # #
        # . . # #
        . # # # .
        . . # . .
        `)
    basic.pause(500)
    basic.clearScreen()
    basic.pause(500)
    basic.showLeds(`
        . # . # .
        # . # # #
        # . . # #
        . # # # .
        . . # . .
        `)
    basic.pause(500)
    basic.clearScreen()
    basic.pause(500)
})

  • click run main to see if the code works as expected.

Challenge 3

You now have a heart and broken heart flashing! Now plot a new image to alternate in with the heart and broken heart.