这 BBC 微:位 (或 Micro Bit)是由 BBC 设计的基于 ARM 的嵌入式系统,用于英国的计算机教育。 它将提供给英国每一个 11 岁的学生。 该设备是基于 ARM Cortex-M0 处理器,并具有加速度计和磁力计传感器。 在本文中,您将学习如何使用 Micro Bit 开始编程 Fedora.
具有 25 个 LED 显示阵列的 Micro Bit 设备。
在你的 Micro Bit 上安装 Mu
从 Fedora 24 (以及 Fedora 23)、可以安装官方的Python IDE, 亩. 使用 Mu,您可以使用 Micro Bit 学习 Python 和一般编程。 像任何其他官方软件包一样安装它 Fedora:
$ sudo dnf install -y mu
安装软件包后,将您的用户帐户添加到拨出组:
$ sudo usermod -a -G dialout username
注销并重新登录以使更改生效。 然后,您可以将 IDE 作为普通应用程序启动。
这是你第一次打开 Mu 时的样子。
用 Mu 编写你的第一个程序
要编写您的第一个程序,您需要向 Micro Bit 提供输入。 一种方法是使用 Read Eval Print Loop,或 Repl。 要访问设备上的 Repl,请单击 Repl 按钮。 您现在可以开始将标准 Python 3 代码写入 Repl。
在 Micro Bit 上运行程序
现在您可以使用编辑器编写完整的 Python 程序,并将其保存在本地计算机上。 准备就绪后,您可以通过单击“刷新”按钮将其上传到设备。 当代码被刷新到设备中时,Micro Bit 上的黄色 LED 会闪烁。
的完整来源 example 在这篇文章中可以找到下面。 它是由 尼古拉斯·H·托勒维,他还监督了在 BBC Micro Bit 上运行 MicroPython 的工作。 他也是《穆》的上游作者。
# Make the display sparkle. Click button A to show an image for # a moment before the sparkles start again. Click button B to # scroll a friendly message before the sparkles return. # By Nicholas H.Tollervey and released to the Public Domain. # How would you improve this code? from microbit import * import random # A full list of images can be found here: https://bit.ly/1WY221q images = [Image.HAPPY, Image.SAD, Image.GHOST, Image.SKULL, Image.DUCK, Image.UMBRELLA, Image.GIRAFFE, Image.RABBIT, Image.HEART, Image.ANGRY, Image.STICKFIGURE] while True: sleep(20) x = random.randint(0, 4) y = random.randint(0, 4) brightness = random.randint(0, 9) display.set_pixel(x, y, brightness) if button_a.was_pressed(): display.show(random.choice(images)) sleep(500) if button_b.was_pressed(): display.scroll("Hello, World!", delay=100)