EXTEND 2: Let's experiment with another micro:bit input!

The micro:bit's magnetometer returns a number greater than 0 when magnetism is detected.

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

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_light() microbit.show_number(data) data_list = [] time_list = [] my_display = codesters.ScatterPlot(time_list, data_list) time = 0 def interval(): data = microbit.get_light() 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. Light") stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)