Radio Tilt Controller Code

Load this application into the micro:bit (or cyber:bot) you want to use as your tilt controller for your cyber:bot that’s running the radio_tilt_controlled_cyberbot script.

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.

  • If you are in a classroom, adjust the channel= in the script to your assigned channel.
  • Enter, save, and flash radio_tilt_controller into the micro:bit that you will use as the tilt controller.  
  • Verify that both the tilt controller and tilt controlled cyber:bot LED displays show the same tilt control needle 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.
  • Set the (receiver) tilt controlled cyber:bot’s PWR switch to 2.
  • Have fun radio-tilt-controlling your cyber:bot!

Example script: radio_tilt_controller

# radio_tilt_controller

from microbit import *
import math
import radio

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:[needle])

    dictionary = { }
    dictionary['x'] = x
    dictionary['y'] = y
    dictionary['needle'] = needle

    packet = str(dictionary)