pxt-calliope/docs/projects/radio-bridge.md

42 lines
982 B
Markdown
Raw Normal View History

# Radio Bridge
2018-09-12 21:44:19 -07:00
2018-09-13 07:04:45 -07:00
Transfer the packet data received from the radio to the serial port. Use buttons **A** and **B** to select a radio group number.
2018-09-12 21:44:19 -07:00
```typescript
/**
* Download this code and connect the device to the computer.
* Press A and B to select the radio group or change it in the code.
*/
let group = 0
/**
* Send all received packets to serial output
*/
radio.onReceivedNumber(function (receivedNumber) {
2018-09-12 21:44:19 -07:00
radio.writeReceivedPacketToSerial()
led.toggle(Math.randomRange(0, 4), Math.randomRange(0, 4))
})
/**
* Decrement radio group by 1
*/
input.onButtonPressed(Button.A, function () {
group = Math.max(0, group - 1)
radio.setGroup(group)
led.stopAnimation()
basic.showNumber(group)
})
/**
* Increment radio group by 1
*/
input.onButtonPressed(Button.B, function () {
group = Math.min(255, group + 1)
radio.setGroup(group)
led.stopAnimation()
basic.showNumber(group)
})
group = 128
radio.setGroup(group)
2018-09-13 07:04:45 -07:00
```
2018-09-14 08:50:03 -07:00
```package
radio
```