The libraries are located at our github repository https://github.com/adafruit/Adafruit-Trinket-USB/ . You can also just click the button below to download the ZIP file which contains both the Keyboard and Mouse libraries.
Install these as ordinary Arduino libraries, via the Arduino Library Manager (see http://arduino.cc/en/Guide/Libraries or our tutorial on Arduino libraries). Keep in mind that this library is designed specifically for Trinket. (although they can be modified to work with other platforms)
Open up the Arduino Library Manager:
Search for the Trinket USB Keyboard library and install it
/* TrinketKeyboard example For Trinket by Adafruit Industries */ #include <TrinketKeyboard.h> #define PIN_BUTTON_CAPITAL_A 0 #define PIN_BUTTON_STRING 2 void setup() { // button pins as inputs pinMode(PIN_BUTTON_CAPITAL_A, INPUT); pinMode(PIN_BUTTON_STRING, INPUT); // setting input pins to high means turning on internal pull-up resistors digitalWrite(PIN_BUTTON_CAPITAL_A, HIGH); digitalWrite(PIN_BUTTON_STRING, HIGH); // remember, the buttons are active-low, they read LOW when they are not pressed // start USB stuff TrinketKeyboard.begin(); } void loop() { // the poll function must be called at least once every 10 ms // or cause a keystroke // if it is not, then the computer may think that the device // has stopped working, and give errors TrinketKeyboard.poll(); if (digitalRead(PIN_BUTTON_CAPITAL_A) == LOW) { // this should type a capital A TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_SHIFT, KEYCODE_A); // this releases the key (otherwise it is held down!) TrinketKeyboard.pressKey(0, 0); } if (digitalRead(PIN_BUTTON_STRING) == LOW) { // type out a string using the Print class TrinketKeyboard.print("Hello World!"); } }
Page last edited March 08, 2024
Text editor powered by tinymce.