CAS Community Forums - DW - MAR 2016


Mar 20 2016, 12:15 Useful demos with a micro:bit 

[edited out for anonymity]

[added] MicroPython has the REPL, which is a great way to do 'live coding' with the micro:bit

Press the little keyboard icon labelled REPL in Mu, and you open a command prompt into the Python interpreter that you just loaded onto the micro:bit (just press NEW then FLASH to get a blank python interpreter loaded).

You can then in the bottom window of Mu type:

display.scroll(“hello world”)

and when you press Return, the code executes immediately, and you see hello world on the micro:bit screen.

You can also via the NEW/FLASH route pre store a number of functions on the micro:bit, and then omit to put a main program at the bottom. These functions are then accessible to you, live, at the REPL command prompt, to further enhance your live coding experience.

We’ve used this with countless children at science fairs and they all love the immediate feedback of typing in a command, pressing Return, and something happening on the micro bit.

For example, at the REPL prompt, type this code (I hope the indents come out ok on this forum!)

while True:

    print(accelerometer.get_x(), accelerometer.get_y())


Now as you tilt the micro:bit around, you get a live feed of the accelerometer values scrolling up on the bottom window.

You’re only a couple of small steps away from writing a Python program on your PC/Mac or Raspberry Pi that uses pyserial to read these numbers and do something amazing with the live data.

[edited out for anonymity]

Article Source: CAS Community Forums

Original Page:

Imported: 17 Oct 2016

Original Author: David Whale (permission to reuse here granted by author)

Anonymity Check: Passed (with edits)