Scrolling text across the display is a very useful way to get information from your micro:bit program. When you have your micro:bit on your cyber:bot robot, this is a good way to display values from the robot's sensors.
To scroll text across the display, use the aptly named display.scroll method. The text you want to display goes inside quotation marks " ", and that goes inside the method's parentheses ( ).
#hello from microbit import * display.scroll("Hello")
You should see the word Hello scroll across the display one character at a time.
The first line, #hello is a comment. It is just there for you to read the script's name, but is ignored by the micro:bit. We will look at comments again later!
The second line, from microbit import *, fetches the code that knows how to run the display methods. Every complete example script in these tutorials will have at least one import * statement at the top.
The third line makes the text appear on the display. The "Hello" text in quotation marks is a parameter of the display.scroll method, and so goes inside its parentheses.
The text you want to display isn't the only parameter you can use with display.scroll. You can control the speed at which the text scrolls across the display by adding a an additional parameter to the display.scroll method called delay. The larger the value for delay, the slower the text will scroll.
#hello_goodbye from microbit import * display.scroll("Hello", delay = 500) display.scroll("Goodbye", delay = 150)
You should see the word Hello scroll across the display slowly, then the word Goodbye scroll across the screen quickly.
Be cautious when copying and pasting code with quotation marks! Some types of documents use smart-quote characters “ and ” that will result in a syntax error if you try to use them in a script. If you are receiving a syntax error after copying and pasting code with quotation marks, try erasing and retyping the quotation marks directly in your programming environment, then re-flash the program.