首页 文章

为什么我的Adafruit Trinket键盘代码不起作用

提问于
浏览
0

我想让我的Adafruit Trinket作为键盘工作 . 我正在使用它的标准示例代码,但它一直给我这个编译错误 .

exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

即使我在我的代码中有这个错误,这个错误仍然会弹出 . 我已经尝试了很多不同版本的这个并且搞砸了很多东西,它总是想出这个错误 .

这是我的代码 .

#include <Keyboard.h>

const int buttonPin = 4;          // input pin for pushbutton
int previousButtonState = HIGH;   // for checking the state of a pushButton
int counter = 0;                  // button push counter

void setup() {
  // make the pushButton pin an input:
  pinMode(buttonPin, INPUT);
  // initialize control over the keyboard:
  Keyboard.begin();
}

void loop() {
  // read the pushbutton:
  int buttonState = digitalRead(buttonPin);
  // if the button state has changed,
  if ((buttonState != previousButtonState)
      // and it's currently pressed:
      && (buttonState == HIGH)) {
    // increment the button counter
    counter++;
    // type out a message
    Keyboard.print("You pressed the button ");
    Keyboard.print(counter);
    Keyboard.println(" times.");
  }
  // save the current button state for comparison next time:
  previousButtonState = buttonState;
}

1 回答

  • 0

    Keyboard.h 库适用于具有本机USB支持的官方Arduino板 .

    对于Trinket,您需要使用TrinketKeyboard.h from Adafruit .

相关问题