pxt-calliope/docs/projects/flashing-heart.md
2016-12-08 00:10:00 -08:00

2.1 KiB

flashing heart

~avatar avatar

Use the LEDs to display a flashing heart!

~

Step 1

Use show leds and make your code look like this:

basic.showLeds(`
    . # . # .
    # # # # #
    # # # # #
    . # # # .
    . . # . .`
    );

Step 2

Add a pause to wait and clear screen to turn off the LEDs.

basic.showLeds(`
    . # . # .
    # # # # #
    # # # # #
    . # # # .
    . . # . .`);
basic.pause(500);
basic.clearScreen();

Step 3

Put a forever loop around it to repeat the animation.

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

Step 4

Add a pause to wait after clearing the screen.

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

Send your heartbeats over radio!

Do you have a second @boardname@ at hand? You could use radio and send your heartbeats to other @boardname@ and show a heart when you receive one.

  • move the code in the forever inside a on data packet received handler. The handler will run whenever a message is received from another @boardname@.
  • use send number and pause to broadcast a packet of data every second.
basic.forever(() => {
    radio.sendNumber(0)
    basic.pause(1000)
})
radio.onDataPacketReceived(({receivedNumber}) => {
    basic.showLeds(`
        . # . # .
        # # # # #
        # # # # #
        . # # # .
        . . # . .`);
    basic.pause(500)
    basic.clearScreen()
    basic.pause(500)
})

Download the .hex file onto both @boardname@ and try it out!

radio