匿名
未登录
登录
丢石头百科
搜索
查看“Micro:bit系列教程11:板载应用”的源代码
来自丢石头百科
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
Micro:bit系列教程11:板载应用
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
<span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">本章将介绍Micro:bit的板载应用,主要包括:图像、文本、数学、游戏。 <h1 style="line-height:150%"><span lang="EN-US" style="font-size:15.0pt; line-height:150%;font-family:黑体;font-weight:normal;mso-bidi-font-weight:bold">1.<span style="font-size:15.0pt;line-height:150%;font-family:黑体;font-weight:normal; mso-bidi-font-weight:bold">图像 </h1> <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast">Micro:bit<span style="font-size:12.0pt;line-height:150%; font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">可通过5x5点阵作为屏幕进行相关符号的显示,但对于篇幅较大的符号,可采取分两屏滚动显示的策略。 <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">下面,将通过例程来说明Micro:bit图像的使用,打开makecode,采用积木块的方式编写以下程序: [[File:135808d37k6iy34ye7exi6.png]] <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">在该积木块程序中,首先,将arrows变量设定为创建的大图,在开机无限循环中,将arrows变量定义的图像每隔500ms向左移动1格,当一幅图像偏移完成后,又从头开始进行偏移,下载到Micro:bit可观察该现象。 <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">在下面的例程中,将说明其它几个积木块的使用方法,打开makecode,采用积木块的方式编写以下程序: [[File:135809bm8d20rdm0rdp82n.png]] <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">在该积木块程序中,将arrows变量设定为创建的大图,在无限循环中,一直显示将向左箭头向左偏移2格的图像,下载到Micro:bit可观察该现象。 <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">此外,还可以获取箭头图像,图标图像,以及箭头图像对应的数字。 <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">获取箭头图像: [[File:135809xahcch74g7thwctc.png]] <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">获取图标图像: [[File:135809qoysotczeihedb2z.png]] <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">获取箭头图像对应的数字: [[File:135810l0u0aeaowqvoehxa.png]] <h1 style="line-height:150%"><span lang="EN-US" style="font-size:15.0pt; line-height:150%;font-family:黑体;font-weight:normal;mso-bidi-font-weight:bold">2.<span style="font-size:15.0pt;line-height:150%;font-family:黑体;font-weight:normal; mso-bidi-font-weight:bold">文本 </h1> <span lang="EN-US" style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast">Micro:bit<span style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">提供了一系列字符串方法对应的积木块,下面来分别介绍相应的积木块: <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.1 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">创建字符串 </h2> [[File:135810tzek8ttyb1ey1att.png]] <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">通过该积木块创建对应的字符串,支持ASCII 32-126对应的字符,数字,标点符号和其它一些符号将在屏幕(LED点阵)上面显示为“?”。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.2 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">获取文本的长度 </h2> [[File:135810uvt2rkscvsstrksa.png]] <span style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast">通过该积木块,可获得字符串的长度。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.3 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">拼接字符串 </h2> [[File:135810boc06363pcocxhcn.png]] <span lang="EN-US" style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast"><span style="mso-tab-count: 1"> <span style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">通过该积木块,可将两个字符串拼接为一个字符串。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.4 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">字符串索引 </h2> [[File:135810fj5j10asqq0bccws.png]] <span lang="EN-US" style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast"><span style="mso-tab-count: 1"> <span style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">通过该积木块,可通过字符串索引得到相应的字符,注意索引从0开始。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.5 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">字符串截取 </h2> [[File:135810ffl2p4g0g44nrbb2.png]] <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">通过该积木块,可截取给定字符串从给定索引开始,长度为给定长度的字符串。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.6 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">字符串比较 </h2> [[File:135810puucsensscllssqn.png]] <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">通过该积木块,可将两字符串进行比较,两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或某一字符串比较完为止。设这两个字符串为str1,str2,若str1等于str2,则返回零;若str1小于str2,则返回负数;若str1大于str2,则返回正数。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">2.7 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">字符串转整数 </h2> [[File:135810izuu2k3uu0kkn6j6.png]] <span lang="EN-US" style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast"><span style="mso-tab-count: 1"> <span style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">通过该积木块,可将数字字符串转换成整数。 <h1 style="line-height:150%"><span lang="EN-US" style="font-size:15.0pt; line-height:150%;font-family:黑体;font-weight:normal;mso-bidi-font-weight:bold">3.<span style="font-size:15.0pt;line-height:150%;font-family:黑体;font-weight:normal; mso-bidi-font-weight:bold">数学 </h1> <span lang="EN-US" style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast"><span style="mso-tab-count: 1"> Micro:bit<span style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">板载提供了若干数学运算: <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">3.1<span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">四则运算 </h2> <span lang="EN-US" style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast">Micro:bit<span style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">提供了四则运算积木块,有加减乘除运算,如下所示: [[File:135811wef3z353q5y0fy5e.png]] <span style="font-size:12.0pt; line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-font-family: 宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-fareast">该积木块返回运算结果,是一个数字。 <span lang="EN-US" style="font-size: 12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font:minor-fareast; mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font: minor-fareast"> <span style="font-size:12.0pt;line-height:150%;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">注意:四则运算不支持小数运算,并且,在除法中,将忽略余数。 <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">3.2<span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">产生随机数 </h2> 随机选取从0到某个给定值范围内的随机数: [[File:135811i3co2v004gcar2wc.png]] <span style="font-size:12.0pt; font-family:宋体">随机选取true或false,作为判断条件: [[File:135811e68sggsd4fh4m6mz.png]] <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">3.3 <span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">取余数,最大值,最小值,绝对值 </h2> [[File:135811nxrroceexegxr9ae.png]] <h2><span lang="EN-US" style="font-size:12.0pt;line-height:173%;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">3.4<span style="font-size:12.0pt; line-height:173%;font-family:宋体;mso-ascii-theme-font:minor-fareast;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast">提取ASCII码 </h2> [[File:135811r7zx2x6z27xj12xj.png]] <span lang="EN-US" style="font-size:12.0pt;font-family:宋体; mso-ascii-theme-font:minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font: minor-fareast;mso-hansi-theme-font:minor-fareast"><span style="mso-tab-count: 1"> <span style="font-size:12.0pt;font-family:宋体;mso-ascii-theme-font: minor-fareast;mso-fareast-font-family:宋体;mso-fareast-theme-font:minor-fareast; mso-hansi-theme-font:minor-fareast">该积木块能够提取字符的ASCII码值,得到十进制数字。 <h1 style="line-height:150%"><span lang="EN-US" style="font-size:15.0pt; line-height:150%;font-family:黑体;font-weight:normal;mso-bidi-font-weight:bold">4.<span style="font-size:15.0pt;line-height:150%;font-family:黑体;font-weight:normal; mso-bidi-font-weight:bold">游戏 </h1> <span style="font-size:12.0pt; line-height:150%;font-family:宋体">可基于Micro:bit屏幕(LED点阵),结合按键,加速计,磁力计等,编写属于自己的游戏,并且:Micro:bit提供了方便编写游戏的相关积木块。
返回至
Micro:bit系列教程11:板载应用
。
导航
导航
首页
最近更改
随机页面
MediaWiki帮助
首页
首页
树莓派
主机
配件包
外壳
键鼠
电源
扩展板
显示屏
墨水屏
摄像模块
通信模块
继电器
电机驱动板
游戏机
产品分类
树莓派
Arduino
micro:bit
STM32
Espressif
WiFi模块
蓝牙模块
无线模块
LoRa模块
4G模块
GSM
GPRS
以太网
导航模块
北斗卫星
GPS
LCD
墨水屏
OLED
摄像头
USB模块
串口模块
RS232
RS485
CAN
传感器
温度模块
湿度模块
气压模块
继电器
电机模块
指纹模块
电平转换
音频模块
编程器
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志