2016-06-14 17:12:13 +02:00
|
|
|
# flashing heart
|
|
|
|
|
2016-06-14 18:11:29 +02:00
|
|
|
### ~avatar avatar
|
|
|
|
|
2016-12-08 09:10:00 +01:00
|
|
|
Use the LEDs to display a flashing heart!
|
2016-06-14 18:11:29 +02:00
|
|
|
|
|
|
|
### ~
|
2016-05-28 06:40:59 +02:00
|
|
|
|
|
|
|
## Step 1
|
|
|
|
|
2016-06-14 23:20:45 +02:00
|
|
|
Use [show leds](/reference/basic/show-leds) and make your code look like this:
|
2016-05-28 06:40:59 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.showLeds(`
|
2016-10-13 20:32:25 +02:00
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`
|
|
|
|
);
|
2016-05-28 06:40:59 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Step 2
|
|
|
|
|
2016-06-14 23:20:45 +02:00
|
|
|
Add a [pause](/reference/basic/pause) to wait and [clear screen](/reference/basic/clear-screen) to turn off the LEDs.
|
2016-05-28 06:40:59 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.showLeds(`
|
2016-10-13 20:32:25 +02:00
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`);
|
2016-05-28 06:40:59 +02:00
|
|
|
basic.pause(500);
|
|
|
|
basic.clearScreen();
|
2016-06-11 05:09:18 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Step 3
|
|
|
|
|
2016-12-08 09:10:00 +01:00
|
|
|
Put a [forever loop](/reference/basic/forever) around it to repeat the animation.
|
2016-06-11 05:09:18 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2016-12-08 09:10:00 +01:00
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`
|
|
|
|
);
|
|
|
|
basic.pause(500);
|
|
|
|
basic.clearScreen();
|
2016-06-11 05:09:18 +02:00
|
|
|
})
|
2016-06-11 20:40:09 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Step 4
|
|
|
|
|
|
|
|
Add a [pause](/reference/basic/pause) to wait after clearing the screen.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2016-12-08 09:10:00 +01:00
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`
|
|
|
|
);
|
|
|
|
basic.pause(500);
|
|
|
|
basic.clearScreen();
|
|
|
|
basic.pause(500);
|
2016-06-11 20:40:09 +02:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2016-12-08 09:10:00 +01:00
|
|
|
## Send your heartbeats over radio!
|
2016-06-11 20:40:09 +02:00
|
|
|
|
2016-12-08 09:10:00 +01:00
|
|
|
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.
|
2016-06-11 20:40:09 +02:00
|
|
|
|
2016-12-08 09:10:00 +01:00
|
|
|
* move the code in the **forever** inside
|
|
|
|
a [on data packet received](/reference/radio/on-data-packet-received) handler.
|
|
|
|
The handler will run whenever a message is received from another @boardname@.
|
|
|
|
* use [send number](/reference/radio/send-number) and [pause](/reference/basic/pause)
|
|
|
|
to broadcast a packet of data every second.
|
2016-06-11 20:40:09 +02:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2016-12-08 09:10:00 +01:00
|
|
|
radio.sendNumber(0)
|
|
|
|
basic.pause(1000)
|
|
|
|
})
|
|
|
|
radio.onDataPacketReceived(({receivedNumber}) => {
|
|
|
|
basic.showLeds(`
|
|
|
|
. # . # .
|
|
|
|
# # # # #
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
. . # . .`);
|
|
|
|
basic.pause(500)
|
|
|
|
basic.clearScreen()
|
|
|
|
basic.pause(500)
|
2016-06-11 20:40:09 +02:00
|
|
|
})
|
2016-06-25 23:22:50 +02:00
|
|
|
```
|
2016-12-08 09:10:00 +01:00
|
|
|
|
|
|
|
Download the .hex file onto both @boardname@ and try it out!
|
|
|
|
|
|
|
|
```package
|
|
|
|
radio
|
|
|
|
```
|