0

I am trying to get my Adafruit Trinket working as a keyboard. I am using the standard example code for it but it keeps giving me this compilation error.

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

this error keeps popping up even though i have it in my code. I have tried lots of different versions of this and messed with lots of things and it has always came up with this error.

This is my code.

#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;
}
gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

1

The Keyboard.h library is for the official Arduino boards with native USB support.

For the Trinket you need to use the TrinketKeyboard.h from Adafruit.

gre_gor
  • 6,669
  • 9
  • 47
  • 52