
3.6 高级模块组件
3.6.1 文件读写

文件读写模块
文件读写模块使您可以对EV3程序块上的文件读取和写入数据。

写入的新数据都会按顺序排在原数据的后面,文件中的数据只能按顺序从第一个数据读取。文件关闭前请进行保存。



超声波测量三次距离,把三个数值写入文件读写。读出三个数值并显示在EV3屏幕上。
3.6.2 信息传递



消息传递模块
消息传递模块用于在EV3程序块之间发送蓝牙消息。要发送或接收消息,必须先通过程序块蓝牙菜单或通过蓝牙连接模块连接EV3程序块。
用蓝牙连接好两个程序块,把发送程序、接收程序分别下载到对应的程序块里。就可以用一个EV3程序块遥控另一个EV3程序块了。

针对两个程序块选择“设置”选项卡,并打开“蓝牙”菜单。
互相搜索到对应程序块后,选择蓝牙连接。




3.6.3 蓝牙连接

使用蓝牙连接模块的前提条件是:对应的程序块必须打开蓝牙,在蓝牙搜索列表里互相都有蓝牙连接的历史记录(就是程序块之间互相都成功建立过蓝牙连接)。如果没有蓝牙连接的历史记录,蓝牙连接模块有可能会失败,导致程序错误。
一个主EV3程序块可以连接到多达7个从EV3程序块。主EV3程序块可以向每个从EV3程序块发送消息。但是从EV3程序块只能将消息发送回主EV3程序块。从EV3程序块不能直接向其他从EV3程序块发送消息。

建立蓝牙连接的时候,请注意程序块的名字要写正确。消息传递模块的程序块名字要写正确。对应到正确的程序块和消息接收模块。
3.6.4 未校准电机

未校准电机模块
与常规中型电机模块和大型电机模块不同,未调整电机模块不包括自动电机控制。这表示不会包括任何针对电机功率的自动调整。

这是实时显示A,B电机功率的程序。




这是官方平衡小子的大型电机控制程序,使用了未校准电机模块控制平衡。
3.6.5 电机反转、停止

反转电机模块
反转电机模块会更改电机的旋转方向。在反转电机方向时,通常使电机顺时针转动的编程模块会改为使电机逆时针转动。

B电机正转1圈,A电机反转1圈,A电机正转一圈,循环。

停止模块
停止模块会立即终止所有编程模块序列并结束程序。

在EV3屏幕中间显示计时器的数值,程序块的红灯闪烁。按下程序块按钮(上),停止运行整个程序。
3.6.6 数据日志、原始传感器值
在EV3屏幕上同时显示端口1、2、3、4的传感器原始数值,并使用数据日志模块保存到EV3程序块里,生成一个记录文件MyData。


数据日志模块
数据日志模块用于收集和保存来自传感器的数据。

原始传感器值模块
原始传感器值模块输出未处理的传感器读数,这是处于范围0到4095中的值。原始传感器值模块只有一种模式。
3.6.7 注释

注释模块
可使用注释模块在程序中写注释。该模块并非编程模块,也就是说没有任何可编程操作与其关联。该模块通常用于对后续的模块以及预期的操作进行解释。
3.6.8 数据线
使用多任务驱动小车,并播放声音。


数据线:实时显示超声波测量的距离。当距离小于6厘米时退出循环,播放Hello。

使用陀螺仪的角度值,实时控制EV3文字在屏幕上左右移动。


超声波传感器检测的距离值,实时改变矩形的长度。