Load this application into the micro:bit (or cyber:bot) you want to use as your tilt controller.
The radio_tilt_controller script is just radio_tilt_controller_w_stop_range from Receiver Full Tilt Control & Stop Range. It is repeated here for folks who skip the majority of the tutorial and go directly to running the application.
- Make sure you are working in the browser with the micro:bit Python Editor that is connected to the radio tilt controller micro:bit.
- Depending on the path you took to get here, your last micro:bit transmitter script might either be radio_tilt_transmit_test or radio_tilt_controller_w_stop_range. If your most recent script is not already open, click Open to load it into the editor.
- Set the project name to radio_tilt_controller.
- Update the script to match the one shown below.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
Example script: radio_tilt_controller
# radio_tilt_controller from microbit import * import math import radio radio.on() radio.config(channel=7, queue=1, length=64) while True: x = accelerometer.get_x() y = accelerometer.get_y() angle = round( math.degrees( math.atan2(y, x) ) ) needle = ( angle + 90 + 15 ) // 30 if abs(y) > 80: display.show(Image.ALL_CLOCKS[needle]) else: display.show(Image.DIAMOND_SMALL) dictionary = { } dictionary['x'] = x dictionary['y'] = y dictionary['needle'] = needle packet = str(dictionary) radio.send(packet) sleep(50)
- Set the Set the (receiver) tilt controlled cyber:bot’s PWR switch to 1.
- Verify that both the tilt controller and tilt controlled cyber:bot LED displays show matching tilt control needles as you tilt the controller micro:bit in various directions.
- Verify that the LED displays show the diamond when you hold the tilt controller level.
- Disconnect the cyber:bot from USB and place it on the floor or in a designated navigation pen.
- Set the (receiver) tilt controlled cyber:bot’s PWR switch to 2.
- Have fun radio-tilt-controlling your cyber:bot!