EXTEND 3: Let's experiment with one final micro:bit input!

The micro:bit's roll detector returns a number that lets us know how far it's tilted to the right or left.

  • Inside your interval event, find the line that says this: data·=·microbit.get_magnet()
  • Replace the text that says .get_magnet() with .get_roll().
  • Then, find the line in which you set the title of your scatter plot. Change the title to "Time vs. Roll".

To navigate the page using the TAB key, first press ESC to exit the code editor.

microbit = codesters.Microbit() microbit.show_string("hello") data = microbit.get_magnet() microbit.show_number(data) data_list = [] time_list = [] my_display = codesters.ScatterPlot(time_list, data_list) time = 0 def interval(): data = microbit.get_magnet() data_list.append(data) global time time_list.append(time) my_display.update(time_list, data_list) time += 1 my_display.set_title("Time vs. Magnetism") stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)