我将一个连接到 Arduino mini pro (3.3v) 的 NES 控制器和一个蓝牙 HID 模块(类似于 rn-42 BlueSmirf)放在一起。我可以将它连接到我的 Macbook 并发送击键。
但是,它的作用就像是重复按下键而不是按住键。我需要它像键盘一样工作,但现在它每次通过循环(50ms)时都会按下一个键。我在这里先向您的帮助表示感谢!
Arduino代码:
const int buttonA = 2;//Button: A
const int buttonB = 3;//Button: B
const int buttonC = 4;//Button: Start
const int buttonD = 5;//Button: Select
const int buttonE = 6;//Button: Up
const int buttonF = 7;//Button: Down
const int buttonG = 8;//Button: Left
const int buttonH = 9;//Button: Right
...
void loop()
{
if (digitalRead(buttonA) == LOW) //pin is HIGH until a button is pressed
{Serial.write('A');}
if (digitalRead(buttonB) == LOW)
{Serial.write('B');}
if (digitalRead(buttonC) == LOW)
{Serial.write('1');}
if (digitalRead(buttonD) == LOW)
{Serial.write('2');}
if (digitalRead(buttonE) == LOW)
{Serial.write('U');}
if (digitalRead(buttonF) == LOW)
{Serial.write('D');}
if (digitalRead(buttonG) == LOW)
{Serial.write('L');}
if (digitalRead(buttonH) == LOW)
{Serial.write('R');}
delay(50);
}