Radiodocsupdate (#1430)
* 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:
@ -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
|
||||
```
|
||||
|
Reference in New Issue
Block a user