2016-08-09 03:12:34 +02:00
|
|
|
# messenger
|
|
|
|
|
|
|
|
![](/static/mb/projects/a9-radio.png)
|
|
|
|
|
|
|
|
Use the radio to create an app that sends "YO" messages.
|
|
|
|
|
|
|
|
## Step 1
|
|
|
|
|
|
|
|
Use [on button pressed](/reference/input/on-button-pressed) to send the number "0" over radio.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.A, () => {
|
|
|
|
radio.sendNumber(0);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## Step 2
|
|
|
|
|
2016-10-25 01:30:21 +02:00
|
|
|
Use [radio on data packet received](/reference/radio/on-data-packet-received) display "YO" when the number ``0`` is received
|
2016-08-09 03:12:34 +02:00
|
|
|
by radio.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let message = 0;
|
2016-10-25 01:30:21 +02:00
|
|
|
radio.onDataPacketReceived(({ receivedNumber }) => {
|
|
|
|
message = receivedNumber;
|
2016-08-09 03:12:34 +02:00
|
|
|
if (message == 0) {
|
|
|
|
basic.showString("YO")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2016-08-18 22:17:05 +02:00
|
|
|
Download the program and **upload the same .hex file to 2 devices!**
|
2016-08-09 03:12:34 +02:00
|
|
|
|
|
|
|
## Step 3
|
|
|
|
|
|
|
|
Use [on button pressed](/reference/input/on-button-pressed) to send the number "1" over radio.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
input.onButtonPressed(Button.B, () => {
|
|
|
|
radio.sendNumber(1);
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## Step 4
|
|
|
|
|
2016-10-25 01:30:21 +02:00
|
|
|
Add blocks in [radio on data packet received](/reference/radio/on-data-packet-received) to display "BYE" when the number ``1`` is received
|
2016-08-09 03:12:34 +02:00
|
|
|
by radio.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let message = 0;
|
2016-10-25 01:30:21 +02:00
|
|
|
radio.onDataPacketReceived(({ receivedNumber }) => {
|
|
|
|
message = receivedNumber;
|
2016-08-09 03:12:34 +02:00
|
|
|
if (message == 0) {
|
|
|
|
basic.showString("YO")
|
|
|
|
}
|
|
|
|
if (message == 1) {
|
|
|
|
basic.showString("BYE")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```package
|
2016-10-23 06:29:31 +02:00
|
|
|
radio
|
2016-08-09 03:12:34 +02:00
|
|
|
```
|