我正在为Arduino编写一个简单的程序,该程序将输入2个按钮和输出模拟键,以在克隆英雄中使用2个不同的功能。
arduino编辑器(在线和本地版本)吐出
'Keyboard' was not declared in this scope
离线编辑器询问是否包括键盘。
有什么想法为什么?
// Keyboard - Version: Latest
#include <Keyboard.h>
//btnWhammy is the button to replace whammy bar function
//btnSP is the button to replace star power activation
//Set Clone Hero to register j for whammy and k for star power
//declaring constant integers for the pins on the Arduino
const int btnWhammy = 2;
const int btnSP = 13;
//Declaring integers for the state of the button press
int btnWhammyState = 0;
int btnSPState = 0;
void setup() {
//Initialisation of the pins as inputs
pinMode(btnWhammy, INPUT);
pinMode(btnSP, INPUT);
}
void loop() {
//Setting the button states to the read of the digital pin (LOW is off, HIGH is on)
btnWhammyState = digitalRead(btnWhammy);
btnSPState = digitalRead(btnSP);
//If the whammy button is pressed, send 'j' to the keyboard, wait 100ms then release all keys
if (btnWhammyState == HIGH) {
Keyboard.press('j');
delay(100);
Keyboard.releaseAll();
}
//If the Star Power button is pressed, send 'k' to the keyboard, wait 100ms then release all keys
if (btnSPState == HIGH) {
Keyboard.press('k');
delay(100);
Keyboard.releaseAll();
}
}
这是一个经典的错误 - 您可能正在为非Leonardo董事会编译,例如UNO。不包括键盘。h库,因为它不适合您要编译的板。
。我拿了您的代码并为Leonardo编辑 - 没有问题。对于uno,我遇到的错误与您相同...
在此范围中没有声明键盘键,我发现了一个非常简单且有效的问题,只需转到您的主文件,您可以在其中声明您面对的所有其他键note
#include <DigiKeyboard.h>
#define KEY_UP_ARROW 0x52
#define KEY_DOWN_ARROW 0x51
#define KEY_LEFT_ARROW 0x50
#define KEY_RIGHT_ARROW 0x4F
#define KEY_TAB 0x2B