Christmas Bauble

 """
by Jez Dean / Public Domain
"""

# import the microbit module
from microbit import *

# scroll "ho ho ho" across the microbit display
# Quotes ("") denote that it's a string
display.scroll("ho ho ho")
 

Code Explained

from microbit import *

This imports the microbit module into the program. * imports everything in the module.

Since we only use the display module, we could use from microbit import display.

display.scroll("ho ho ho")

Scrolls the text across the micro:bit’s display. Everything inside the " is shown in the display. Characters within " are strings.

Reading the API

The microbit API for the display module describes a delay parameter for the scroll method.

display.scroll("ho ho ho", delay=500) updates the display every 500 milliseconds (or half a second). It slows down the speed of the scrolling text.

The API documentation has information that microbit module. Try reading it when you’re coding for ideas. The Python community are also famously helpful - search online for mailing lists and message boards that may contain the help you need. If in doubt, ask for help.

Going Further

This only scrolls the message once. Read the API to make it repeat.

Strings & Integers

Integers

Integers are numbers. Python understands numbers and can perform calculations with them:

3 + 1 = 4 

1 * 4 = 16

Strings

A string is a list of characters which python does not understand. Strings are always surronded by "quotation" marks.

"dog" + "cat" = dogcat

We can also have numerals in a string:

"5" + "2"` = 52. 

Python does not understand a string. It only understands what the characters look like.

Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Christmas Bauble

Make a simple Christmas bauble to scroll a festive message across the display.

Jez Dean
Teacher