
1.4.3 Blocks Editor界面设计
接下来,需要为组件添加行为,使程序能够对一些动作(比如说触摸屏幕)做出反应(如变换图像、发出声音等)。单击Blocks按钮进入Blocks Editor界面,在左侧列表中找到需要编写响应的组件;单击它,在它的右侧会产生该组件可以创建的事件列表类型。选择一种需要的事件块并拖到右边的编辑区,为事件编写相应的内容。
实现步骤如下:
1.对屏幕进行初始化
在没有完成“搜索蓝牙”之前,“连接蓝牙”按钮处于非活动状态,即不可点击。
1)点击Blocks Editors界面左侧的Screen1选项卡,在Screen1右边会弹出一个列表,选择Screen1.Initialize,并拖曳到右侧空白编辑区。
2)点击Screen1选项卡,选择Button2,从Button2右边列表中选择Button2.Enabeld,并拖曳到Screen1.Initialize框内。
3)点击Built-In选项卡,选择Logic,从Logic右边列表中选择false,并拖曳到右边Button2.Enabeld的槽口处连接在一起,如图1.20所示。

图1.20 Screen1初始化
2.“搜索蓝牙”键设计
利用ListPicker组件实现“搜索蓝牙”键展开功能,将手机已存储配对过的设备做成一个列表供我们选择。
定义一个全局变量DeviceMac,用来存放选择后的蓝牙Mac地址。
1)从Built-In选项卡找到Variables,选择initialize.global,并拖曳到右边编辑区,并将变量名name修改为DeviceMac。
2)从Built-In选项卡中找到Text;选择text,拖曳到右边DeviceMac的槽口,将text修改为ok,完成DeviceMac初始化赋值,如图1.21所示。

图1.21 定义一个全局变量DeviceMac
在选择蓝牙前,ListPicker组件需要先列出手机配对过的设备清单。
模块需求如表1.1所示。
表1.1 “搜索蓝牙”按钮选择蓝牙前行为定义列表

在选择蓝牙后,DeviceMac保存从列表中选择的Mac地址,并将“连接蓝牙”按钮激活。
模块需求如表1.2所示。
表1.2 “搜索蓝牙”按钮选择蓝牙后行为定义列表

模块组装后如图1.22所示。

图1.22 “搜索蓝牙”键设计
3.“连接蓝牙”键设计
设计思路如图1.23所示。

图1.23 “连接蓝牙”键设计逻辑框图
模块需求如表1.3所示。
表1.3 “连接蓝牙”按钮行为定义模块需求列表

“连接蓝牙”键完整设计如图1.24所示。

图1.24 “连接蓝牙”键设计
4.“灯泡按钮”键设计
设计思路:
1)点击熄灭灯泡的图案时,把熄灭灯泡的图案换成点亮灯泡的图案。在Button1.Click框内把Button1.Image修改为light2.png,并通过蓝牙向Arduino主控板发送命令数值16。
2)再次点击时,把点亮灯泡的图案换成熄灭灯泡的图案。在Button1.Click框内把Button1.Image修改为light1.png,并通过蓝牙向Arduino主控板发送命令数值17。
模块需求如表1.4所示。
表1.4 “灯泡按钮”行为定义模块需求列表

“灯泡按钮”键完整设计如图1.25所示。

图1.25 “灯泡按钮”键设计