设备
https://item.taobao.com/item.htm?spm=a1z09.2.0.0.50122e8dJH3bCJ&id=547198899364&_u=51qf7bf5dd52
安装库
https://github.com/T-vK/ESP32-BLE-Mouse
下载zip
软件添加库
烧录
选择版型
选择程序例子
烧录时候 需要按着boot按键,结束后松开,按下reset按键
电脑或者手机连接蓝牙
串口输出,电脑跟着改变
单纯蓝牙控制例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <Arduino.h> #include <BluetoothSerial.h> BluetoothSerial SerialBT; const int ledPin1 = 2 ; / / LED1连接的引脚 const int ledPin2 = 4 ; / / LED2连接的引脚 void setup() { Serial.begin( 115200 ); SerialBT.begin( "ESP32_LED" ); / / 蓝牙设备名称 pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); Serial.println( "蓝牙已初始化,可以通过蓝牙控制LED" ); } void loop() { if (SerialBT.available()) { char command = SerialBT.read(); / / 读取蓝牙数据 switch (command) { case '1' : digitalWrite(ledPin1, HIGH); / / 点亮LED1 SerialBT.println( "LED1已点亮" ); / / 反馈信息 break ; case '2' : digitalWrite(ledPin1, LOW); / / 熄灭LED1 SerialBT.println( "LED1已熄灭" ); / / 反馈信息 break ; case '3' : digitalWrite(ledPin2, HIGH); / / 点亮LED2 SerialBT.println( "LED2已点亮" ); / / 反馈信息 break ; case '4' : digitalWrite(ledPin2, LOW); / / 熄灭LED2 SerialBT.println( "LED2已熄灭" ); / / 反馈信息 break ; } } } |
上下左右切换视频滑动
鼠标初次链接自动出现在正中间
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <BleMouse.h> BleMouse bleMouse; void setup() { Serial.begin( 115200 ); Serial.println( "Starting BLE work!" ); bleMouse.begin(); } void loop() { if (bleMouse.isConnected()) { unsigned long startTime; Serial.println( "上滑" ); bleMouse.move( 0 , 0 , 1 ); / / 视频切换 微信一个对话框宽度 delay( 2000 ); Serial.println( "下滑" ); bleMouse.move( 0 , 0 , - 1 ); delay( 2000 ); Serial.println( "右滑" ); bleMouse.move( 0 , 0 , 0 , 1 ); delay( 2000 ); Serial.println( "左滑" ); bleMouse.move( 0 , 0 , 0 , - 1 ); delay( 2000 ); } } |
鼠标点击样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | / * * * This example turns the ESP32 into a Bluetooth LE mouse that continuously moves the mouse. * / #include <BleMouse.h> BleMouse bleMouse; void setup() { Serial.begin( 115200 ); Serial.println( "Starting BLE work!" ); bleMouse.begin(); } void loop() { if (bleMouse.isConnected()) { Serial.println( "Left click" ); bleMouse.click(MOUSE_LEFT); delay( 500 ); Serial.println( "Right click" ); bleMouse.click(MOUSE_RIGHT); delay( 500 ); Serial.println( "Scroll wheel click" ); bleMouse.click(MOUSE_MIDDLE); delay( 500 ); Serial.println( "Back button click" ); bleMouse.click(MOUSE_BACK); delay( 500 ); Serial.println( "Forward button click" ); bleMouse.click(MOUSE_FORWARD); delay( 500 ); Serial.println( "Click left+right mouse button at the same time" ); bleMouse.click(MOUSE_LEFT | MOUSE_RIGHT); delay( 500 ); Serial.println( "Click left+right mouse button and scroll wheel at the same time" ); bleMouse.click(MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE); delay( 500 ); } } |
鼠标滑动和点击样例2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | / * * * This example turns the ESP32 into a Bluetooth LE mouse that continuously moves the mouse. * / #include <BleMouse.h> BleMouse bleMouse; void setup() { Serial.begin( 115200 ); Serial.println( "Starting BLE work!" ); bleMouse.begin(); } void loop() { if (bleMouse.isConnected()) { unsigned long startTime; Serial.println( "Scroll up" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , 0 , 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Scroll down" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , 0 , - 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Scroll left" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , 0 , 0 , - 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Scroll right" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , 0 , 0 , 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Move mouse pointer up" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , - 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Move mouse pointer down" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 0 , 1 ); delay( 100 ); } delay( 500 ); Serial.println( "Move mouse pointer left" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( - 1 , 0 ); delay( 100 ); } delay( 500 ); Serial.println( "Move mouse pointer right" ); startTime = millis(); while (millis()<startTime + 2000 ) { bleMouse.move( 1 , 0 ); delay( 100 ); } delay( 500 ); } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
2021-11-12 python 一份简单的车辆环视全景系统实现
2020-11-12 pyqt5开发(1)部署环境aconda安装
2019-11-12 树莓派4 (1)一键配置