The radio_tilt_receive_test script is a modified version of countdown_receiver from the Cybersecurity: Radio Data’s Send and Receive Packets [1] activity. To receive and display tilt, it is adjusted to parse x, y, and needle values from the packet it receives, and then use statements from display_tilt_down_with_leds to display the tilt with its LEDs and in the terminal.
For best results:
# radio_tilt_receive_test from microbit import * import radio radio.on() radio.config(channel=7, queue=1, length=64) sleep(1000) while True: packet = radio.receive() if packet: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') print("Receive:") print("x =", x, ", y =", y, ", needle =", needle) print() display.show(Image.ALL_CLOCKS[needle]) sleep(500)
The goal is to be able to tilt the transmitting micro:bit, and verify matching data in the receive terminal, and on the receiver micro:bit’s LEDs. So, you will be tilting the transmitter while monitoring the receiver.
Links
[1] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-data/send-and-receive-packets