我正在为Arduino编写一个简单的程序,它将输入2个按钮并输出2个不同功能的模拟键,以便在Clone Hero中使用。
Arduino编辑器(在线和本地版本)吐出
'Keyboard' was not declared in this scope
离线编辑器询问是否包含Keyboard.h ......显然是。
任何想法为什么?
// 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();
}
}
答案 0 :(得分:2)
这是一个经典的错误 - 你可能正在为一个非莱昂纳多董事会编译,就像Uno一样。不包括Keyboard.h库,因为它不适用于您正在编译的电路板。
我拿了你的代码并为莱昂纳多编译 - 没有问题。对于Uno,我得到了和你一样的错误......
答案 1 :(得分:0)
在此范围内未声明键盘键,我发现了此问题的一个非常简单且有效的窍门,只需转到您的主文件,即可在其中声明您面临的所有其他键而未声明
#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