有什么方法可以发送这个Keyboard.Press();通过蓝牙向我的电脑发出无线命令?

问题描述 投票:0回答:1

我已经能够通过蓝牙实现我的Arduino Micro板的无线数据发送。我使用以下代码将传感器数据从 arduino 板发送到 PC。但我希望它能够执行 Keyboard.Press();根据我从连接到微板上的传感器收到的数据。

有没有办法发送这个Keyboard.Press();通过蓝牙向我的电脑发出无线命令?

我使用 Arduino Micro 和 HC-05 将数据无线发送到 PC。

#include <SoftwareSerial.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU9250.h"

MPU9250 accelgyro;
I2Cdev   I2C_M;

int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
float Axyz[3];

const int rxPort = 8; // connected to Bluetooth TX
const int txPort = 9; // connected to Bluetooth RX
SoftwareSerial myConnection = SoftwareSerial(rxPort, txPort);

void setup() {
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Initializing I2C devices...");
  accelgyro.initialize();
  Serial.println("Testing device connections...");
  Serial.println(accelgyro.testConnection() ? "MPU9250 connection successful" : "MPU9250 connection failed");
  delay(1000);
  myConnection.begin(9600);

}

void loop() 
{
  myConnection.print(mapX);
  myConnection.print("  ,  ");
  myConnection.println(mapY);
  ////Keyboard.press('a');
}
c++ arduino bluetooth
1个回答
0
投票

对于蓝牙 v2,您需要一个支持 HID 的蓝牙模块。当我知道这个产品时

https://www.sparkfun.com/products/retired/10938

但现在他们退休了。

如果你想升级到蓝牙 v4,我不知道。在网络上搜索似乎您需要实施“HID over GATT profile”(HOGP)。

我找到了一些BLE芯片(nRF8001、nRF2740/nRF2741)的这个库,其中有蓝牙键盘的示例;否则,如果您已经有 BT4 板,请尝试寻找实现该配置文件的库,或尝试将其移植到您的平台。

当然,这仅适用于蓝牙 4 板,因为蓝牙 2 有一些固定的“类”(因此您无法将 BT 串行适配器变成 BT-HID 设备)。

© www.soinside.com 2019 - 2024. All rights reserved.