回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

基于Mind+平台的蓝牙翻页笔项目 简单

头像 rzegkly 2020.12.28 833 1
project-image

一、【作品介绍】

作为一名教师在作ppt演示时,我们经常都碰到这样的尴尬,需要一边操作电脑一边讲解,行动上受到限制,很不方便。如何让我们在教学演示时彻底解放出来,真正实现"走到哪里,讲到哪里,讲到哪里,指到哪里"。今天分享一个《鳄霸王蓝牙翻页笔》项目,让我们老师们在教学时充分发挥肢体语言,让教学更生动,更完美,解决在课堂上使用鼠标的不便的问题。

project-image

二、【思路】

1.当掌控板与WIN10之间的蓝牙配对成功,控制PPT幻灯片播放状态

2.打开鳄霸王显示文字信息:鳄霸王蓝牙翻页笔,

3. 当蓝牙连接成功后,RGB绿灯点亮,等待接受按键指令,

4.按下A键时,开始播放ppt,按下B键时,停止播放ppt

5.摇杆向上拨动,ppt翻上一页, 摇杆向下拨动,ppt翻下一页,

材料清单

  • 掌控板 X1
  • 鳄霸王拓展板 X2
  • 蓝牙接收模块 X3

三、【测试数据】

鳄霸王的摇杆上下连接掌控板P0口,左右连接P1口,现在对数据进行测试。

project-image

1.打开Mind+v1.6.5,连接设备COM17;

project-image

2.左下角点击扩展添加主控板:掌控板;

project-image

3.点左侧掌控模块,找到引脚操作指令;

project-image

4.测试摇杆的数值

project-image

四、【编写程序】

1.打开Mind+v1.6.5,连接设备COM17;

project-image

2.左下角点击扩展添加主控板:掌控板;

用户库:输入蓝牙,添加蓝牙键盘模块;

project-image

3.点左侧用户库模块,找到ESP32蓝牙相关指令;

project-image

4.编写程序

如果蓝牙配对失败,掌控板rgb显示红灯;

如果蓝牙配对成功,掌控板rgb显示蓝灯;

如果收到掌控板A键发送的蓝牙数据;发出蓝牙键盘F5指令;

如果收到掌控板B键发送的蓝牙数据;发出蓝牙键盘ESC指令;

如果收向上拨动摇杆的蓝牙数据;发出蓝牙键盘方向向上指令;

如果收向下拨动摇杆的蓝牙数据;发出蓝牙键盘方向向下指令;

project-image
project-image
project-image
代码
/*!
 * MindPlus
 * mpython
 *
 */
#include <MPython.h>
#include <BleKeyboard.h>
// 创建对象
BleKeyboard bleKeyboard("2020BLE", "Espressif", 100);


// 主程序开始
void setup() {
	mPython.begin();
	bleKeyboard.begin();
	rgb.write(-1, 0xFF0000);
	display.setCursorLine(1);
	display.printLine("鳄霸王蓝牙翻页笔");
}
void loop() {
	if (bleKeyboard.isConnected()) {
		display.setCursorLine(2);
		display.printLine("BLE Keyboard");
		display.setCursorLine(3);
		display.printLine("蓝牙已经连接成功!");
		display.setCursorLine(4);
		display.printLine("准备接指令......");
		delay(100);
		rgb.write(-1, 0x0000FF);
		if ((buttonA.isPressed())) {
			display.fillInLine(4, 0);
			display.setCursorLine(4);
			display.printLine("开始播放");
			bleKeyboard.press(KEY_F5);
			delay(100);
			bleKeyboard.releaseAll();
			delay(1000);
		}
		if ((buttonB.isPressed())) {
			display.fillInLine(4, 0);
			display.setCursorLine(4);
			display.printLine("结束播放");
			bleKeyboard.press(KEY_ESC);
			delay(100);
			bleKeyboard.releaseAll();
			delay(1000);
		}
		if (((analogRead(P0))==0)) {
			display.fillInLine(4, 0);
			display.setCursorLine(4);
			display.printLine("上一页");
			bleKeyboard.press(KEY_UP_ARROW);
			delay(100);
			bleKeyboard.releaseAll();
			delay(1000);
		}
		if (((analogRead(P0))==4095)) {
			display.fillInLine(4, 0);
			display.setCursorLine(4);
			display.printLine("下一页");
			bleKeyboard.press(KEY_DOWN_ARROW);
			delay(100);
			bleKeyboard.releaseAll();
			delay(1000);
		}
	}
}

五、【蓝牙连接】

通过编写程序已经将掌控板模拟成了蓝牙键盘,我们需要将掌控板和电脑进行配对,这样控制PPT的播放。

以 Windows 10 系统为例,其他系统类似。

project-image

步骤1 进入Windows设置,找到添加蓝牙设备,蓝牙和其他设备。

project-image

步骤2 打开蓝牙按钮,点击最上面的“+”号,准备添加蓝牙设备。

project-image

步骤3 3. 进入添加设备界面,搜寻蓝牙设备,添加蓝牙的类型

project-image

步骤4 如果连接成功,掌控板rgb灯,由红灯变为蓝灯,等待掌控板发出指令…

project-image

六、总结

        采用了Arduino 代码模拟蓝牙键盘进行编程,我们学习相关语法,比如:ESP32 蓝牙键盘库、BleKeyboard 对象、begin() 和 end() 函数、press() 函数、release() 函数、releaseAll() 函数、write() 函数、isConnected() 函数、print() 函数等相关语法,而使用Mind+的图性化编程 ,将程序封装在图形模块中,操作简单,思路清晰,容易上手!

评论

user-avatar
  • hacker_

    hacker_2023.05.04

    666

    0