The traditional way to start programming in a new language is to get your computer to say, “Hello, World!”. This is easy with MicroPython: from microbit import * display.scroll("Hello, World!") Each line does something special. The first line: from microbit import * …tells MicroPython to get all the stuff it needs to work with the BBC
micro:bit. All this stuff is in a module called The second line: display.scroll("Hello, World!") …tells MicroPython to use the display to scroll the string of characters
“Hello, World!”. The Copy the “Hello, World!” code into your editor and flash it onto the device. Can you work out how to change the message? Can you make it say hello to you? For example, I might make it say “Hello, Nicholas!”. Here’s a clue, you need to change the scroll method’s argument. Warning It may not work. :-) This is where things get fun and MicroPython tries to be helpful. If it encounters an error it will scroll a helpful message on the micro:bit’s display. If it can, it will tell you the line number for where the error can be found. Python expects you to type EXACTLY the right thing. So, for instance,
If MicroPython complains about a Your microbit may stop responding: you cannot flash new code to it or enter commands into the REPL. If this happens, try power cycling it. That is, unplug the USB cable (and battery cable if it’s connected), then plug the cable back in again. You may also need to quit and re-start your code editor application. |
|
来自: 昵称69363700 > 《待分类》