К основному контенту

micropython

Hello, World!

The traditional way to start programming in a new language is to get your computer to say, “Hello, World!”.
../_images/scroll-hello1.gif
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 microbit (a module is a library of pre-existing code). When you import something you’re telling MicroPython that you want to use it, and * is Python’s way to say everything. So, from microbit import * means, in English, “I want to be able to use everything from the microbit code library”.
The second line:
display.scroll("Hello, World!")
…tells MicroPython to use the display to scroll the string of characters “Hello, World!”. The displaypart of that line is an object from the microbit module that represents the device’s physical display (we say “object” instead of “thingy”, “whatsit” or “doodah”). We can tell the display to do things with a full-stop . followed by what looks like a command (in fact it’s something we call a method). In this case we’re using the scroll method. Since scroll needs to know what characters to scroll across the physical display we specify them between double quotes (") within parenthesis (( and )). These are called the arguments. So, display.scroll("Hello, World!") means, in English, “I want you to use the display to scroll the text ‘Hello, World!’”. If a method doesn’t need any arguments we make this clear by using empty parenthesis like this: ().
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.

Комментарии

Популярные сообщения из этого блога

micro:bit

Our micro:bit curriculum materials are designed for seasoned STEM pros, first-time users, and everyone in-between – check out these free resources here:  http://msft.social/HOU20E

Новогодний мастер-класс по созданию ёлочной игрушки

Задачи мастер-класса: 1) Дать возможность родителям познакомиться с цифровыми инструментами, с которыми работают в школе их дети. 2) Дать возможность родителям провести время с детьми в активном взаимодействии. 3) Показать возможности scratch как открытого инструмента с широкими возможностями, не замкнутого на самом себе. 4) Показать способ быстрого и простого входа в тему 3D-моделирования. 5) Показать возможности 3d-печати для личного использования. Этапы моделирования: 1) В графическом редакторе Scratch рисуем один луч снежинки 2) С помощью скрипта делаем полный оборот костюма с печатью в каждом положении 3) Экспорт полученного изображения в PNG 4) Конвертация в SVG 5) Импорт SVG в Tinkercad 6) Редактирование 3d-модели Пример луча: Пример скрипта: Пример снежинки: Пример 3d-модели GoogleDocs:  bit.ly/1540NY .

micro:Python

https://codewith.mu/en/tutorials/1.0/start https://gimn-microbit.blogspot.com/p/1.html