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

42 lines
982 B
Markdown
Raw Normal View History

2018-09-13 06:44:19 +02:00
# Radio bridge
2018-09-13 16:04:45 +02: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-13 06:44:19 +02: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-13 06:44:19 +02: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 16:04:45 +02:00
```
2018-09-14 17:50:03 +02:00
```package
radio
```