* a few updates

* more updates

* reorder radio blocks

* more shuffling of new radio apis

* fixing hot or ocold

* more doc fixes

* more updates

* fixing docs issues

* more doc fixes

* restore docs errors

* missing packate

* renamed argument of callback

* mssing radio

* more odcs fixes

* lock turtle

* ignore docs for now
This commit is contained in:
Peli de Halleux 2018-10-15 15:32:09 -07:00 коммит произвёл GitHub
Родитель 11fbbea5bd
Коммит 2b504d863d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
49 изменённых файлов: 218 добавлений и 136 удалений

Просмотреть файл

@ -50,15 +50,6 @@
## #examples
* [Examples](/examples)
* [Blinky](/examples/blinky)
* [Rando](/examples/rando)
* [Plot Acceleration](/examples/plot-acceleration)
* [Plot Light Level](/examples/plot-light-level)
* [Game of Life](/examples/gameofLife)
* [Egg and Spoon Race](/examples/egg-and-spoon)
* [Radio Dashboard](/examples/radio-dashboard)
## #courses
* [Courses](/courses)
@ -223,10 +214,14 @@
* [send number](/reference/radio/send-number)
* [send value](/reference/radio/send-value)
* [send string](/reference/radio/send-string)
* [on data packet received](/reference/radio/on-data-packet-received)
* [on received number](/reference/radio/on-received-number)
* [on received string](/reference/radio/on-received-string)
* [on received buffer](/reference/radio/on-received-buffer)
* [received packet](/reference/radio/received-packet)
* [set group](/reference/radio/set-group)
* [set transmit power](/reference/radio/set-transmit-power)
* [set transmit serial number](/reference/radio/set-transmit-serial-number)
* [on data packet received](/reference/radio/on-data-packet-received)
* [write received packet to serial](/reference/radio/write-received-packet-to-serial)
* [Game](/reference/game)
* [create sprite](/reference/game/create-sprite)

Просмотреть файл

@ -46,8 +46,7 @@ Here is the complete Marco Polo program:
input.onButtonPressed(Button.A, () => {
radio.sendString("Marco")
})
radio.onDataPacketReceived(({ receivedString }) => {
radio.onReceivedString(function (receivedString) {
basic.showString(receivedString)
})
input.onButtonPressed(Button.B, () => {
@ -69,7 +68,7 @@ input.onButtonPressed(Button.A, () => {
radio.sendString("Marco")
music.playTone(131, music.beat(BeatFraction.Whole))
})
radio.onDataPacketReceived( ({ receivedString }) => {
radio.onReceivedString(function (receivedString) {
basic.showString(receivedString)
})
input.onButtonPressed(Button.B, () => {
@ -134,7 +133,7 @@ In order to know whether to display a dot, a dash, or a space/stop image, we nee
* Leave the righthand side default value of zero in the 0=0 block.
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
}
@ -145,7 +144,7 @@ radio.onDataPacketReceived( ({ receivedNumber }) => {
* Create an image to represent a dot.
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showLeds(`
. . . . .
@ -168,7 +167,7 @@ Challenge question: How can we fix this?
* Add a 'pause' block and a 'clear screen' block after the 'show leds' block
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showLeds(`
. . . . .
@ -198,7 +197,7 @@ Now each time the sender presses button A, you see a dot appear.
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showLeds(`
. . . . .
@ -282,7 +281,7 @@ input.onButtonPressed(Button.B, () => {
input.onButtonPressed(Button.AB, () => {
radio.sendNumber(2)
})
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showLeds(`
. . . . .

Просмотреть файл

@ -27,7 +27,7 @@ Second micro:bit that plays the notes
```blocks
let sound = 0
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
sound = 349
music.playTone(sound, music.beat(BeatFraction.Half))

Просмотреть файл

@ -89,7 +89,7 @@ basic.forever(() => {
This receiver @boardname@ uses the “on start” event to set up the title on the @boardname@ when started, the radio group, and the ``bodyElectricity`` variable to collect and store the data received.
The ``||radio:on radio received||`` event reads the number value sent from the sending @boardname@. The number is then stored in the ``bodyElectricity`` variable. the electricity on pin **0** and stores it in the variable ``bodyElectricity``. The last line uses the serial write command to send the text `"Body Electricity"` label and the value of ``bodyElectricity`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second.
The ``||radio:on received number||`` event reads the number value sent from the sending @boardname@. The number is then stored in the ``bodyElectricity`` variable. the electricity on pin **0** and stores it in the variable ``bodyElectricity``. The last line uses the serial write command to send the text `"Body Electricity"` label and the value of ``bodyElectricity`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second.
```blocks
// Body Electricity Receiver
@ -98,7 +98,7 @@ let bodyElectricty = 0
radio.setGroup(99)
// Radio Receiver event
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
bodyElectricty = receivedNumber
serial.writeValue("Body Electricty", bodyElectricty)
})

Просмотреть файл

@ -85,7 +85,7 @@ In the radio received event, the temperature is received from sending the micro:
let temperature = 0
radio.setGroup(99)
basic.showString("TEMPERATURE RECEIVER")
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber)
})
```
@ -99,7 +99,7 @@ This code is the same as above but one additional line of code is added to write
let temperature = 0
basic.showString("TEMPERATURE RECEIVER SERIAL")
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber)
serial.writeValue("Celisus", receivedNumber)
})
@ -143,14 +143,14 @@ basic.showString("GRAVITY RECEIVER")
radio.setGroup(99)
```
The ``||radio:on radio received||`` event will constantly monitor radio signals from the radio group.
The ``||radio:on received number||`` event will constantly monitor radio signals from the radio group.
When a value is received from the group it is stored in the ``gravity`` variable.
The ``||serial:serial write value||`` sends 2 pieces of data back to the MakeCode app through the USB cable. First it sends a label `"gravity"` and then the value received as gravity from the ``||input:acceleration||`` method from the first micro:bit.
```blocks
basic.showString("GRAVITY RECEIVER")
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
serial.writeValue("gravity", receivedNumber)
})
```

Просмотреть файл

@ -52,7 +52,7 @@ radio.setGroup(99)
#### Code the receive event
7. The ``||radio:on radio received||`` event will constantly monitor radio signals from the radio group.
7. The ``||radio:on received number||`` event will constantly monitor radio signals from the radio group.
8. When a value is received from the group it is stored in the ``gravity`` variable.
9. The ``||serial:serial write Value||`` sends 2 pieces of data back to the MakeCode app through the USB cable. First it sends a label `"gravity"` and then the value received as gravity from the acceleration method from the first @boardname@.
10. Add a ``||led:toggle||`` to indicate that it's receiving data. Change ``x`` to `1` so that another LED blinks.
@ -60,8 +60,8 @@ radio.setGroup(99)
```blocks
basic.showString("GRAVITY RECEIVER")
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber: gravity }) => {
serial.writeValue("gravity", gravity)
radio.onReceivedNumber(function (receivedNumber) {
serial.writeValue("gravity", receivedNumber)
led.toggle(1, 0)
})
```

Просмотреть файл

@ -71,11 +71,11 @@ radio.setGroup(10)
serial.writeLine("Acceleration")
```
The ``||radio:on radio received||`` event reads the number value from the sending @boardname@. The number is then stored in the variable ``receivedNumber``. The last line uses the serial write command to send the text ``"z"`` label and the value of ``receivedNumber`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second.
The ``||radio:on received number||`` event reads the number value from the sending @boardname@. The number is then stored in the variable ``receivedNumber``. The last line uses the serial write command to send the text ``"z"`` label and the value of ``receivedNumber`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second.
```blocks
// onRadio receive & write z value to serial
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
serial.writeValue("z", receivedNumber)
})
```

Просмотреть файл

@ -102,14 +102,14 @@ basic.forever(() => {
In the starting of the code the title is displayed, radio group `99` is setup, and the initial ``temperature`` variable is set to `0`.
In the ``||radio:on radio received||`` event, the temperature is received from sending the @boardname@ radio. The receive temperature is then displayed on the LED display. This is repeated whenever a radio signal is received.
In the ``||radio:on received number||`` event, the temperature is received from sending the @boardname@ radio. The receive temperature is then displayed on the LED display. This is repeated whenever a radio signal is received.
```blocks
let temperature = 0
basic.showString("TEMPERATURE RADIO RECEIVER")
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber: temperature }) => {
basic.showNumber(temperature)
radio.onReceivedNumber( function(receivedNumber) {
basic.showNumber(receivedNumber)
})
```
@ -121,9 +121,9 @@ This code is the same as above but one additional line of code is added to write
let temperature = 0
basic.showString("TEMPERATURE RADIO RECEIVER SERIAL")
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber: temperature }) => {
basic.showNumber(temperature)
serial.writeValue("Celisus", temperature)
radio.onReceivedNumber( function(receivedNumber) {
basic.showNumber(receivedNumber)
serial.writeValue("Celisus", receivedNumber)
})
```

Просмотреть файл

@ -14,11 +14,11 @@ The receiving @boardname@ sets a radio group number on which to listen for incom
radio.setGroup(99)
```
The receiver then waits to receive a packet (radio message) from the sender which contains the data to record. This happens inside an ``||radio:on radio received||`` block. If the sending @boardname@ is measuring temperature at a remote location (somewhere else in the room maybe), the receiver will write the value received as a temperature measurement to the serial port.
The receiver then waits to receive a packet (radio message) from the sender which contains the data to record. This happens inside an ``||radio:on received number||`` block. If the sending @boardname@ is measuring temperature at a remote location (somewhere else in the room maybe), the receiver will write the value received as a temperature measurement to the serial port.
```blocks
radio.setGroup(99)
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber)
serial.writeValue("TempCelsius", receivedNumber)
})
@ -67,14 +67,14 @@ Here's the program for the receiver to record both temperature and light:
```blocks
radio.setGroup(99)
radio.onDataPacketReceived(({ receivedString: name, receivedNumber: value }) => {
radio.onReceivedValue(function (name: string, value: number) {
basic.showString(name + ":")
basic.showNumber(value)
serial.writeValue(name, value)
})
```
The receiver program uses just one ``||radio:on radio received||`` event to record the values. The ``name`` and the ``value`` are parameters for the event block so both temperature and light values are received here.
The receiver program uses just one ``||radio:on received number||`` event to record the values. The ``name`` and the ``value`` are parameters for the event block so both temperature and light values are received here.
## Multiple remote stations
@ -111,8 +111,10 @@ basic.forever(() => {
The program on the receiver board can use the serial number to make a name value pair that the [Data Viewer](./writing#name-value-pairs) can recognize:
```blocks
let id = 0;
radio.setGroup(99)
radio.onDataPacketReceived(({ serial: id, receivedString: name, receivedNumber: value }) => {
radio.onReceivedValue(function (name: string, value: number) {
id = radio.receivedPacket(RadioPacketProperty.SerialNumber)
basic.showString(name + ":")
basic.showNumber(value)
serial.writeValue(id + "_" + name, value)
@ -126,7 +128,7 @@ The serial number, ``id``, is used as a _prefix_ for the ``name`` to identify wh
If you're recording data to save on a computer for analysis or other uses outside of the MakeCode editor, you can use the ``||radio:radio write received packet to serial||`` block to format it for you. This function will format the data from the received packet into a [JSON](https://en.wikipedia.org/wiki/JSON) string and write it to the serial port, all in one operation. It's used just like this:
```blocks
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
radio.writeReceivedPacketToSerial();
});
```

Просмотреть файл

@ -52,13 +52,14 @@ function getClient(id: number): Client {
}
// store data received by clients
radio.onDataPacketReceived(packet => {
const client = getClient(packet.serial);
radio.onReceivedNumber(function (receivedNumber) {
const serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
const client = getClient(serialNumber);
if (!client)
return;
client.ping = input.runningTime()
client.sprite.setBrightness(Math.max(1, packet.receivedNumber & 0xff));
client.sprite.setBrightness(Math.max(1, receivedNumber & 0xff));
})
// monitor the sprites and start blinking when no packet is received

Просмотреть файл

@ -63,7 +63,7 @@ input.onButtonPressed(Button.A, () => {
input.onButtonPressed(Button.B, () => {
radio.sendString("B")
})
radio.onDataPacketReceived(({receivedString}) => {
radio.onReceivedNumber(({ receivedString }) => {
basic.showString(receivedString)
})
```

Просмотреть файл

@ -22,7 +22,7 @@ Learn the functions of **on data received**, **send number** and **receive numbe
input.acceleration(Dimension.X)
led.plotBarGraph(0, 1023)
basic.showNumber(0)
radio.onDataPacketReceived(() => {})
radio.onReceivedNumber(function (receivedNumber) {})
radio.sendNumber(0)
```

Просмотреть файл

@ -28,7 +28,7 @@ We want to register code to run when a packet is received over radio. We can imp
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
})
```
@ -39,7 +39,7 @@ Finally, we want to chart the acceleration. So we must first implement `plot bar
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(receivedNumber, 1023)
})

Просмотреть файл

@ -31,7 +31,7 @@ basic.showLeds(`
`)
basic.clearScreen()
if (true) {}
radio.onDataPacketReceived(() => { })
radio.onReceivedNumber(function (receivedNumber) { })
```
## Objectives

Просмотреть файл

@ -120,7 +120,7 @@ input.onButtonPressed(Button.AB, () => {
let jumps = 0
basic.showNumber(jumps)
})
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber)
})
@ -151,7 +151,7 @@ input.onButtonPressed(Button.AB, () => {
let jumps = 0
basic.showNumber(jumps)
})
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
basic.showNumber(receivedNumber)
led.stopAnimation()
})

Просмотреть файл

@ -21,7 +21,7 @@ Learn how to **show LEDs** to turn on a LED light pattern on the LED screen. We
basic.forever(() => {});
radio.sendNumber(0);
input.acceleration(Dimension.Strength)
radio.onDataPacketReceived(() => {});
radio.onReceivedNumber(function (receivedNumber) {});
led.plotBarGraph(0, 0);
```

Просмотреть файл

@ -78,7 +78,7 @@ Your finished code will look like this:
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.Strength) - 1023);
});
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
});
```
@ -92,7 +92,7 @@ Your finished code will look like this:
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.Strength) - 1023);
});
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(receivedNumber, 0);
});
```

Просмотреть файл

@ -87,7 +87,7 @@ When a firefly receives a radio packet, it increments its clock by one:
```block
// the clock ticker
let clock = 0
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
// advance clock to catch up neighbors
clock += 1
})
@ -104,7 +104,7 @@ Download this program on as many @boardname@s as you can find and try it out in
```blocks
// the clock ticker
let clock = 0
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
// advance clock to catch up neighbors
clock += 1
})

Просмотреть файл

@ -55,8 +55,10 @@ The hunter @boardname@ looks for beacons.
To determine how far away or how close they are, we use the signal strength of each radio packet sent by the beacons. The signal strength ranges from ``-128db`` (weak) to ``-42db`` (very strong).
```blocks
radio.onDataPacketReceived( ({ receivedNumber, signal }) => {
basic.showNumber(signal)
let signal = 0;
radio.onReceivedNumber(function (receivedNumber) {
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
basic.showNumber(signal);
});
radio.setGroup(1)
```
@ -84,8 +86,9 @@ Here is an example that uses ``-95`` or less for cold, between ``-95`` and ``-80
To make the program more responsive, add a ``||led:stop animation||`` to cancel icon animations when a new beacon packet comes in.
```blocks
radio.onDataPacketReceived( ({ receivedNumber, signal }) => {
led.stopAnimation();
let signal = 0;
radio.onReceivedNumber(function (receivedNumber) {
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
if (signal < -90) {
basic.showIcon(IconNames.SmallDiamond)
} else if (signal < -80) {
@ -121,9 +124,13 @@ To check if an array contains an certain element, we use the ``||arrays:find ind
```blocks
let beacons: number[] = [0]
radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => {
if (signal > -50 && beacons.indexOf(serial) < 0) {
beacons.push(serial)
let signal = 0;
let serialNumber = 0;
radio.onReceivedNumber(function (receivedNumber) {
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
if (signal > -50 && beacons.indexOf(serialNumber) < 0) {
beacons.push(serialNumber)
game.addScore(1)
basic.showNumber(game.score())
}
@ -146,7 +153,11 @@ The hunter code with all th pieces together looks like this now. Download and tr
```blocks
let beacons: number[] = [0];
radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => {
let signal = 0;
let serialNumber = 0;
radio.onReceivedNumber(function (receivedNumber) {
signal = radio.receivedPacket(RadioPacketProperty.SignalStrength)
serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
led.stopAnimation();
if (signal < -95) {
basic.showIcon(IconNames.SmallDiamond)
@ -154,8 +165,8 @@ radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => {
basic.showIcon(IconNames.Diamond)
} else {
basic.showIcon(IconNames.Square)
if (signal > -50 && beacons.indexOf(serial) < 0) {
beacons.push(serial)
if (signal > -50 && beacons.indexOf(serialNumber) < 0) {
beacons.push(serialNumber)
game.addScore(1)
basic.showNumber(game.score())
}

Просмотреть файл

@ -11,7 +11,7 @@ Remote control your inchworm with another @boardname@
You will need one more @boardname@ for this part. By using the radio, we can control the inchworm with another @boardname@. Download the code below to the @boardname@ on the inchworm and then again onto a "controller" @boardname@. Whenever button **A** is pressed, the inchworm moves once.
```blocks
radio.onDataPacketReceived(({receivedNumber}) => {
radio.onReceivedNumber(({ receivedNumber }) => {
pins.servoWritePin(AnalogPin.P0, 0)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 180)

Просмотреть файл

@ -11,7 +11,7 @@ Remote control your monster with another @boardname@.
You will need one more @boardname@ for this part. By using the radio, we can control the monster with another @boardname@. Download the code below to the @boardname@ on the monster and then again onto a "controller" @boardname@. Whenever button **A** is pressed, the monster's mouth moves once.
```blocks
radio.onDataPacketReceived(({receivedNumber}) => {
radio.onReceivedNumber(({ receivedNumber }) => {
pins.servoWritePin(AnalogPin.P0, 30)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 150)

Просмотреть файл

@ -12,7 +12,7 @@ You will need 2 @boardname@ for this part. By using the radio, we can make the M
Download the code below to the @boardname@ on the Milk Carton Monster and another "controller" @boardname@. Whenere ``A`` is pressed, the Milk Carton Monster will move once.
```blocks
radio.onDataPacketReceived(({receivedNumber}) => {
radio.onReceivedNumber(({ receivedNumber }) => {
pins.servoWritePin(AnalogPin.P0, 0)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 180)

Просмотреть файл

@ -12,7 +12,7 @@ You will need a second @boardname@ for this part. By using the radio, we can con
Download the code below to the @boardname@ that's on the Milky Monster and again to another "controller" @boardname@. Whenever button **A** is pressed, the Milky Monster will move one time.
```blocks
radio.onDataPacketReceived(({receivedNumber}) => {
radio.onReceivedNumber(({ receivedNumber }) => {
pins.servoWritePin(AnalogPin.P0, 0)
basic.pause(500)
pins.servoWritePin(AnalogPin.P0, 180)

Просмотреть файл

@ -23,12 +23,12 @@ input.onButtonPressed(Button.A, () => {
## Receiving a smiley
We add a ``||radio:on radio received||`` block that will run code whenever a new "mood" message comes in.
We add a ``||radio:on received number||`` block that will run code whenever a new "mood" message comes in.
The ``receivedNumber`` variable contains the numeric value that was sent. Since we've decided that
`0` is **smiley**, we add a conditional ``||logic:if then||`` statement to show this icon.
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showIcon(IconNames.Happy)
}
@ -46,10 +46,10 @@ input.onButtonPressed(Button.B, () => {
})
```
If the ``||radio:on radio received||`` block, we add another conditional ``||logic:if then||`` statement to handle the **frowny** "mood code".
If the ``||radio:on received number||`` block, we add another conditional ``||logic:if then||`` statement to handle the **frowny** "mood code".
```blocks
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showIcon(IconNames.Happy)
}
@ -76,7 +76,7 @@ input.onButtonPressed(Button.B, () => {
radio.sendNumber(1)
basic.showIcon(IconNames.Sad)
})
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
if (receivedNumber == 0) {
basic.showIcon(IconNames.Happy)
}

Просмотреть файл

@ -89,3 +89,7 @@ radio.onReceivedNumber(function (receivedNumber) {
}
})
```
```package
radio
```

Просмотреть файл

@ -11,7 +11,7 @@ let group = 0
/**
* Send all received packets to serial output
*/
radio.onDataPacketReceived(function () {
radio.onReceivedNumber(function (receivedNumber) {
radio.writeReceivedPacketToSerial()
led.toggle(Math.randomRange(0, 4), Math.randomRange(0, 4))
})

Просмотреть файл

@ -7,10 +7,10 @@ https://youtu.be/XXesoUC0XBU
We can use the radio on the @boardname@ to control the toy car remotely.
A second @boardname@ will send commands to control the throttle and the steering.
```blocks-ignore
```blocks
let steering = 0
let throttle = 0
radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) => {
radio.onReceivedValue(function (name: string, value: number) {
led.toggle(0, 0)
if (name == "throttle") {
if (value > 0) {

Просмотреть файл

@ -97,7 +97,7 @@ let players: number[] = [0]
## Step 4: Receiving a message (part 1)
In an ``||radio:on radio received||`` event, we receive the status from another @boardname@. Click on the **gearwheel** to add the ``serial`` parameter as we will need it to identify who sent that packet.
In an ``||radio:on received number||`` event, we receive the status from another @boardname@. Click on the **gearwheel** to add the ``serial`` parameter as we will need it to identify who sent that packet.
We compute three values from the data received:
@ -111,7 +111,9 @@ let player_index = 0
let players: number[] = [0]
let tool = 0
let found = false
radio.onDataPacketReceived(({ receivedNumber, serial: serialNumber }) => {
let serialNumber = 0;
radio.onReceivedNumber(function (receivedNumber) {
serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
match = tool == receivedNumber
player_index = players.indexOf(serialNumber)
found = player_index >= 0
@ -134,7 +136,9 @@ let players: number[] = [0]
let tool = 0
let found = false
let temp = 0
radio.onDataPacketReceived(({ receivedNumber, serial: serialNumber }) => {
let serialNumber = 0;
radio.onReceivedNumber(function (receivedNumber) {
serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
match = tool == receivedNumber
player_index = players.indexOf(serialNumber)
found = player_index >= 0
@ -183,11 +187,9 @@ let player_index = 0
let tool = 0
let match = false
let players: number[] = []
input.onGesture(Gesture.Shake, () => {
players = [0]
tool = Math.randomRange(0, 3)
})
radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => {
let serialNumber = 0;
radio.onReceivedNumber(function (receivedNumber) {
serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber)
match = tool == receivedNumber
player_index = players.indexOf(serialNumber)
found = player_index >= 0
@ -198,6 +200,10 @@ radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => {
temp = players.removeAt(player_index)
}
})
input.onGesture(Gesture.Shake, () => {
players = [0]
tool = Math.randomRange(0, 3)
})
basic.forever(() => {
radio.sendNumber(tool)
if (tool == 0) {

Просмотреть файл

@ -77,7 +77,7 @@ input.onGesture(Gesture.Shake, () => {
### Receiving the potato
Receiving the potato is done in the [``||radio:on radio received||``](/reference/radio/on-data-packet-received) block.
Receiving the potato is done in the [``||radio:on received number||``](/reference/radio/on-received-number) block.
The **receivedNumber** represents the potato and is stored in the **potato** variable.
```blocks

Просмотреть файл

@ -31,5 +31,5 @@ basic.forever(() => {
```
```package
microturtle=github:Microsoft/pxt-microturtle#master
microturtle=github:Microsoft/pxt-microturtle#v0.0.9
```

Просмотреть файл

@ -31,5 +31,5 @@ basic.forever(() => {
```
```package
microturtle=github:Microsoft/pxt-microturtle#master
microturtle=github:Microsoft/pxt-microturtle#v0.0.9
```

Просмотреть файл

@ -74,5 +74,5 @@ input.onButtonPressed(Button.A, function() {
```
```package
microturtle=github:Microsoft/pxt-microturtle#master
microturtle=github:Microsoft/pxt-microturtle#v0.0.9
```

Просмотреть файл

@ -21,7 +21,7 @@ input.onButtonPressed(Button.A, () => {
music.playTone(440, 120)
led.toggle(0, 0)
})
radio.onDataPacketReceived( ({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
const freq = receivedNumber >> 16;
const duration = receivedNumber & 0xffff;
music.playTone(freq, duration);

Просмотреть файл

@ -34,7 +34,7 @@ thing from nearby @boardname@s. It shows these numbers as a
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
})
radio.onDataPacketReceived(({ receivedNumber }) => {
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(receivedNumber, 1023);
})
```

Просмотреть файл

@ -1,6 +1,6 @@
# On Data Received
> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead.
> Note: This API has been deprecated! Use [on received number](/reference/radio/on-received-number) instead.
Run part of a program when the @boardname@ receives a
[number](/types/number) or [string](/types/string) over ``radio``.
@ -28,7 +28,7 @@ radio.onDataReceived(() => {
## See also
[on data packet received](/reference/radio/on-data-packet-received),
[on received number](/reference/radio/on-received-number),
[send number](/reference/radio/send-number), [set group](/reference/radio/set-group)
```package

Просмотреть файл

@ -0,0 +1,58 @@
# on Received Buffer
Run part of a program when the @boardname@ receives a buffer over ``radio``.
```sig
radio.onReceivedBuffer(function (receivedBuffer) {})
```
## Parameters
* **receivedBuffer**: The buffer that was sent in this packet or the empty string if this packet did not contain a string. See [send buffer](/reference/radio/send-buffer)
## Example: Remote level
If you load this program onto two @boardname@s, each board will send the level information to the other board.
```typescript
let ax = 0;
let ay = 0;
basic.forever(() => {
ax = input.acceleration(Dimension.X);
ay = input.acceleration(Dimension.Y);
// encode data in buffer
let buf = pins.createBuffer(4)
buf.setNumber(NumberFormat.Int16LE, 0, ax)
buf.setNumber(NumberFormat.Int16LE, 2, ay)
radio.sendBuffer(buf)
})
radio.onReceivedBuffer(function (receivedBuffer) {
// decode data from buffer
ax = receivedBuffer.getNumber(NumberFormat.Int16LE, 0);
ay = receivedBuffer.getNumber(NumberFormat.Int16LE, 2);
// display
basic.clearScreen()
led.plot(
pins.map(ax, -1023, 1023, 0, 4),
pins.map(ay, -1023, 1023, 0, 4)
)
});
```
## ~hint
A radio that can both transmit and receive is called a _transceiver_.
## ~
## See also
[send buffer](/reference/radio/send-buffer)
```package
radio
```

Просмотреть файл

@ -40,7 +40,7 @@ basic.forever(() => {
})
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(
Math.abs(radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength) + 42),
Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42),
128 - 42
)
})
@ -54,7 +54,7 @@ The radio set group might need to be set, synchronized , before the radio events
## See also
[on received strig](/reference/radio/on-received-string),
[on received string](/reference/radio/on-received-string),
[send number](/reference/radio/send-number),
[send string](/reference/radio/send-string),
[send value](/reference/radio/send-value),

Просмотреть файл

@ -1,6 +1,6 @@
# Receive Number
> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead.
> Note: This API has been deprecated! Use [on received number](/reference/radio/on-received-number) instead.
Receives the next number sent by a @boardname@ in the same ``radio`` group.

Просмотреть файл

@ -1,6 +1,6 @@
# Receive String
> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead.
> Note: This API has been deprecated! Use [on received string](/reference/radio/on-received-string) instead.
Find the next string sent by `radio` from another @boardname@.

Просмотреть файл

@ -1,9 +1,9 @@
# get Received Packet Property
# Received Packet Property
Get one of the properties from the last received radio packet.
```sig
radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength)
radio.receivedPacket(RadioPacketProperty.SignalStrength)
```
## Parameters
@ -28,7 +28,7 @@ basic.forever(() => {
})
radio.onReceivedNumber(function (receivedNumber) {
led.plotBarGraph(
Math.abs(radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength) + 42),
Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42),
128 - 42
)
})
@ -37,3 +37,7 @@ radio.onReceivedNumber(function (receivedNumber) {
## See also
[set transmit serial number](/reference/radio/set-transmit-serial-number)
```package
radio
```

Просмотреть файл

@ -7,7 +7,7 @@ Find how strong the ``radio`` signal is, from `-128` to `-42`.
The @boardname@ finds the signal strength by checking how strong it was
the last time it ran the
[on data packet received](/reference/radio/on-data-packet-received) function. That means
[on received number](/reference/radio/on-received-number) function. That means
it needs to run **receive number** first.
```sig
@ -39,7 +39,7 @@ basic.forever(() => {
## See also
[on data packet received](/reference/radio/on-data-packet-received), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
[on received number](/reference/radio/on-received-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received)
```package
radio

Просмотреть файл

@ -30,7 +30,7 @@ basic.forever(() => {
radio.sendBuffer(buf)
})
radio.onDataPacketReceived(({ receivedBuffer }) => {
radio.onReceivedBuffer(function (receivedBuffer) {
// decode data from buffer
ax = receivedBuffer.getNumber(NumberFormat.Int16LE, 0);
ay = receivedBuffer.getNumber(NumberFormat.Int16LE, 2);
@ -52,7 +52,7 @@ A radio that can both transmit and receive is called a _transceiver_.
## See also
[on data packet received](/reference/radio/on-data-packet-received)
[on received buffer](/reference/radio/on-received-buffer)
```package
radio

Просмотреть файл

@ -35,7 +35,7 @@ radio.setTransmitPower(7)
## See also
[get received packet property](/reference/radio/get-received-packet-property),
[received packet](/reference/radio/received-packet),
[send number](/reference/radio/send-number),
[send value](/reference/radio/send-value),
[send string](/reference/radio/send-string)

Просмотреть файл

@ -20,7 +20,7 @@ radio.setTransmitSerialNumber(true);
## See also
[get received packet property](/reference/radio/get-received-packet-property),
[received packet property](/reference/radio/received-packet),
[send number](/reference/radio/send-number),
[send value](/reference/radio/send-value),
[send string](/reference/radio/send-string)

Просмотреть файл

@ -36,7 +36,7 @@ input.onButtonPressed(Button.A, () => {
});
radio.onDataPacketReceived(() => {
radio.onReceivedNumber(function (receivedNumber) {
radio.writeReceivedPacketToSerial();
});
```

Просмотреть файл

@ -8,8 +8,6 @@
"radio.Packet.time": "The system time of the sender of the packet at the time the packet was sent.",
"radio._packetProperty": "Gets a packet property.",
"radio._packetProperty|param|type": "the packet property type, eg: PacketProperty.time",
"radio.getReceivedPacketProperty": "Returns properties of the last radio packet received.",
"radio.getReceivedPacketProperty|param|type": "the type of property to retrieve from the last packet",
"radio.onDataPacketReceived": "Registers code to run when the radio receives a packet. Also takes the\nreceived packet from the radio queue.",
"radio.onDataReceived": "Registers code to run when a packet is received over radio.",
"radio.onReceivedBuffer": "Registers code to run when the radio receives a buffer.",
@ -21,6 +19,8 @@
"radio.receiveString": "Reads the next packet from the radio queue and returns the packet's string\npayload or the empty string if the packet did not contain a string.",
"radio.receivedBuffer": "Returns the buffer payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\npacket did not contain a string.",
"radio.receivedNumber": "Returns the number payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or 0 if that packet did not\ncontain a number.",
"radio.receivedPacket": "Returns properties of the last radio packet received.",
"radio.receivedPacket|param|type": "the type of property to retrieve from the last packet",
"radio.receivedSerial": "Returns the serial number of the sender micro:bit from the last packet taken\nfrom the radio queue (via ``receiveNumber``, ``receiveString``, etc) or 0 if\nthat packet did not send a serial number.",
"radio.receivedSignalStrength": "Gets the received signal strength indicator (RSSI) from the last packet taken\nfrom the radio queue (via ``receiveNumber``, ``receiveString``, etc). Not supported in simulator.\nnamespace=radio",
"radio.receivedString": "Returns the string payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\npacket did not contain a string.",

Просмотреть файл

@ -1,9 +1,8 @@
{
"radio.PacketProperty.SerialNumber|block": "serial number",
"radio.PacketProperty.SignalStrength|block": "signal strength",
"radio.PacketProperty.Time|block": "time",
"RadioPacketProperty.SerialNumber|block": "serial number",
"RadioPacketProperty.SignalStrength|block": "signal strength",
"RadioPacketProperty.Time|block": "time",
"radio._packetProperty|block": "%note",
"radio.getReceivedPacketProperty|block": "received packet %type=radio_packet_property",
"radio.onDataPacketReceived|block": "on radio received",
"radio.onDataReceived|block": "radio on data received",
"radio.onReceivedBuffer|block": "on radio received",
@ -13,6 +12,7 @@
"radio.raiseEvent|block": "radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id",
"radio.receiveNumber|block": "radio receive number",
"radio.receiveString|block": "radio receive string",
"radio.receivedPacket|block": "received packet %type=radio_packet_property",
"radio.receivedSignalStrength|block": "radio received signal strength",
"radio.sendNumber|block": "radio send number %value",
"radio.sendString|block": "radio send string %msg",

Просмотреть файл

@ -1,3 +1,16 @@
enum RadioPacketProperty {
//% blockIdentity=radio._packetProperty
//% block="signal strength"
SignalStrength = 2,
//% blockIdentity=radio._packetProperty
//% block="time"
Time = 0,
//% block="serial number"
//% blockIdentity=radio._packetProperty
SerialNumber = 1
}
/**
* Communicate data using radio packets
*/
@ -33,18 +46,6 @@ namespace radio {
public signal: number;
}
export enum PacketProperty {
//% blockIdentity=radio._packetProperty
//% block="time"
Time,
//% block="serial number"
//% blockIdentity=radio._packetProperty
SerialNumber,
//% blockIdentity=radio._packetProperty
//% block="signal strength"
SignalStrength
}
/**
* Registers code to run when the radio receives a packet. Also takes the
* received packet from the radio queue.
@ -133,7 +134,7 @@ namespace radio {
//% help=radio/on-received-buffer blockHandlerKey="radioreceived" blockHidden=1
//% blockId=radio_on_buffer block="on radio received" blockGap=16
//% useLoc="radio.onDataPacketReceived"
export function onReceivedBuffer(cb: (buffer: Buffer) => void) {
export function onReceivedBuffer(cb: (receivedBuffer: Buffer) => void) {
onDataReceived(() => {
receiveNumber();
const packet = new Packet();
@ -151,14 +152,15 @@ namespace radio {
* Returns properties of the last radio packet received.
* @param type the type of property to retrieve from the last packet
*/
//% help=radio/get-received-packet-property advanced=true
//% blockId=radio_received_packet_property block="received packet %type=radio_packet_property" blockGap=16
export function getReceivedPacketProperty(type: number) {
//% help=radio/received-packet
//% weight=11 blockGap=8
//% blockId=radio_received_packet block="received packet %type=radio_packet_property" blockGap=16
export function receivedPacket(type: number) {
if (lastPacket) {
switch(type) {
case PacketProperty.Time: return lastPacket.time;
case PacketProperty.SerialNumber: return lastPacket.serial;
case PacketProperty.SignalStrength: return lastPacket.signal;
case RadioPacketProperty.Time: return lastPacket.time;
case RadioPacketProperty.SerialNumber: return lastPacket.serial;
case RadioPacketProperty.SignalStrength: return lastPacket.signal;
}
}
return 0;
@ -170,7 +172,7 @@ namespace radio {
*/
//% blockId=radio_packet_property block="%note"
//% shim=TD_ID blockHidden=1
export function _packetProperty(type: PacketProperty): number {
export function _packetProperty(type: RadioPacketProperty): number {
return type;
}
}

Просмотреть файл

@ -240,7 +240,7 @@
"productId": "0x0204",
"rawHID": true
},
"ignoreDocsErrors": true,
"ignoreDocsErrors": true,
"appTheme": {
"accentColor": "#5C005C",
"logoUrl": "https://microbit.org/code/",