我正在尝试使用带有蓝牙 HID 模块(bluesmirf)的 arduino 来控制我的 Galaxy 标签上的音量。我有 arduino 设置,所以我按下一个连接的小按钮,它就像键盘一样将 ascii 文本发送到平板电脑,这很好用。我想为这个“蓝牙键盘”创建一个自定义键盘布局文件,这样当平板电脑通过蓝牙接收来自 arduino 的按键时,它将控制适当的项目,如音量、静音等。但是,当使用 keytest捕获从蓝牙模块按下的传入按钮,扫描码始终为 0。 Keytest 正在读取密钥并在发送 A 时将其显示为 keycode_a (例如),但该键的扫描码始终为 0 而不是唯一的标识符。说来也怪,
我不明白。我一定是做错了什么,但我还是新手/正在学习,所以我一定会错过它。如果没有扫描码供平板电脑查看,我无法设置自定义键盘布局来执行我想要的操作。
如有必要,我可以发布我的 arduino 代码。非常感谢任何和所有帮助。我非常接近完成我需要的东西,这让我发疯。
编辑 - 代码如下:
// test code for sending keystrokes from arduino
// to computer via HID bluetooth module
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// begin serial communication at 115200 baud rate
Serial.begin(115200);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH,
//the LED turns on, and the line is printed via bluetooth.
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // turn LED on:
Serial.println("A"); // write the line via bluetooth
delay(1000); // delay one second
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
所以在上面的代码中,Serial.println("A"); 发送到平板电脑,我可以在文本编辑器中看到打印的 A。平板电脑看到在 keytest 应用程序中按下了 A,但它显示扫描码为 0。由于某种原因,发送的每个字符都显示为 0,除了草图在 Serial.println 之后抛出的自动回车。我什至尝试使用 Serial.print 代替,因为它不会抛出回车,而且我也得到了相同的扫描码 0。