Giter VIP home page Giter VIP logo

adafruit-trinket-usb's Introduction

Adafruit-Trinket-USB

Arduino libraries allowing Trinket to act as USB devices

NOTE: This folder contains multiple libraries. Each library must be installed individually. Simply installing the master folder won't work. Move each library folder out of the master after you unzip into your libraries folder.

adafruit-trinket-usb's People

Contributors

asfyra avatar driverblock avatar frank26080115 avatar ladyada avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit-trinket-usb's Issues

TrinketHidCombo.getLEDstate() not working

Hi!

When using TrinketHidCombo, the function getLEDstate() seems to be returning always 0, but for TrinketKeyboard it works fine!

test code:

// Adafruit Arduino 1.05 - Win 9-15-14
// trinket 5V

#include <Bounce.h>
#include <TrinketKeyboard.h>
//#include <TrinketHidCombo.h>

#define LED_CAPS 1


void setup() {
  pinMode(LED_CAPS,OUTPUT);
  TrinketKeyboard.begin();
  //TrinketHidCombo.begin();
}

void loop() {
  delay(5);

  TrinketKeyboard.poll();
  digitalWrite(LED_CAPS, (TrinketKeyboard.getLEDstate()&KB_LED_CAPS)?HIGH:LOW);
  //TrinketHidCombo.poll();
  //digitalWrite(LED_CAPS, (TrinketHidCombo.getLEDstate()&KB_LED_CAPS)?HIGH:LOW);
}

Keycodes for Mail, Calculator, Search, Home, Favorites, Refresh, Stop, Forward, Back

i found keycodes from : USB HID - Implement "Consumer Device" to allow Volume Up/Down Control?

    0x09, 0xcd, // USAGE (Play/Pause) 0x04
    0x09, 0xb7, // USAGE (Stop) 0x05
    0x09, 0xb6, // USAGE (Scan Previous Track) 0x06
    0x09, 0xb5, // USAGE (Scan Next Track) 0x07
    0x0a, 0x8a, 0x01, // USAGE (Mail) 0x08
    0x0a, 0x92, 0x01, // USAGE (Calculator) 0x09

--
i can use ;

TrinketHidCombo.pressMultimediaKey( 0xcd); for (Play/Pause) 
TrinketHidCombo.pressMultimediaKey( 0xb7); for (Stop) 
TrinketHidCombo.pressMultimediaKey( 0xb6); for (Scan Previous Track) 
TrinketHidCombo.pressMultimediaKey( 0xb5); for (Scan Next Track) 

but how can i use Mail and Calculator vs

USB driver installation issue

Hi,

I have trying to make the TrinketFakeUSBSerial to work. I have been successful expect for the last step as shown in this link (https://learn.adafruit.com/assets/11621)

The Device Manager under Windows recognizes it as an "Unknown Device" under the USB controllers. But when I try to point the *.inf file for installation it come up with the error attached. It states "The folder you specified doesn't contain a compatible software driver for your device. If the folder contains a driver, make sure it is designed to work with Windows for 32-bit systems"

fakeusbserial_usb_driver_error

General bug: initialization and print issues when first connects to USB

There is some sort of initialization bug preventing prints, or reading the LED states, or anything like it, from properly working when you first connect to USB.

Related issue: #12

Here is some sample code to duplicate the issue:

#include <TrinketHidCombo.h>
#include <TrinketHidComboC.h>

void setup()
{
  TrinketHidCombo.begin();  
  
  TrinketHidCompatibleDelay(0); //increase to 2000 to remove the print errors entirely; decrease to 0 to make the errors worse and more frequent; use 1000 to cause occasional initial print errors only
  
  //wait until connected to USB before continuing
  //-note that isConnected() will change to true at that point 
  unsigned long counter = 0;
  while (TrinketHidCombo.isConnected() == false)
  {
    counter++;
    TrinketHidCombo.poll(); //The poll function must be called at least once every 10 ms, or you must command a keystroke. Otherwise, the computer may think that the device has stopped working, and give errors.
  }
  
  TrinketHidCombo.print(F("counter = ")); TrinketHidCombo.print(counter); //DOESN'T PRINT QUITE RIGHT!
  TrinketHidCombo.print(F("; t_ms = ")); TrinketHidCombo.println(millis());  
}

void loop()
{

}

//--------------------------------------------------------------------------------------------
//TrinketHidCompatibleDelay
//-this is a USB-compatible delay, so that the 10ms max time between poll calls is not exceeded
//--------------------------------------------------------------------------------------------
void TrinketHidCompatibleDelay(unsigned int desiredDelay_ms)
{
  unsigned long t_start = millis(); //ms
  while (millis()-t_start<desiredDelay_ms)
  {
    TrinketHidCombo.poll(); //keep the HID USB connection to the computer alive 
  }
}

Sample output, when printing into Notepad (NOT Notepad++, whose autocomplete messes with the output).

Using TrinketHidCompatibleDelay(0) at the beginning of setup():
(notice how messed up it is)
-note: each line below is after a new power reset of the microcontroller (unplug it from USB, then plug it back in)

unter = 41584; t_ms = 596
unter = 40789; t_ms = 590
unter = 42898; t_ms = 601
er = 42847; t_ms = 600
unter = 41137; t_ms = 594
nter = 40832; t_ms = 587
ounter = 41924; t_ms = 599
ter = 180498; t_ms = 1224
nter = 179296; t_ms = 1211
er = 41012; t_ms = 590
nter = 42755; t_ms = 602
er = 182202; t_ms = 1224

Using TrinketHidCompatibleDelay(1000) at the beginning of setup():
(only one erroneous print now)
-note: each line below is after a new power reset of the microcontroller (unplug it from USB, then plug it back in)

counter = 0; t_ms = 1307
counter = 0; t_ms = 1305
counter = 0; t_ms = 1311
counter = 0; t_ms = 1308
counter = 0; t_ms = 1308
counter = 0; t_ms = 1309
counter = 0; t_ms = 1308
ter = 70173; t_ms = 1719
counter = 0; t_ms = 1307
counter = 0; t_ms = 1307
counter = 0; t_ms = 1308
counter = 0; t_ms = 1310
counter = 0; t_ms = 1303
counter = 0; t_ms = 1302
counter = 0; t_ms = 1309
counter = 0; t_ms = 1303
counter = 0; t_ms = 1304
counter = 0; t_ms = 1304
counter = 0; t_ms = 1303
counter = 0; t_ms = 1308
counter = 0; t_ms = 1306
counter = 0; t_ms = 1303
counter = 0; t_ms = 1308
counter = 0; t_ms = 1306
counter = 0; t_ms = 1308
counter = 0; t_ms = 1307

Using TrinketHidCompatibleDelay(2000) at the beginning of setup() pretty much guarantees a successful startup with good prints.

Here's some of its outputs:

counter = 0; t_ms = 2306
counter = 0; t_ms = 2306
counter = 0; t_ms = 2309
counter = 0; t_ms = 2311
counter = 0; t_ms = 2308
counter = 0; t_ms = 2309

Why? Is there a better way? Is this a bug somewhere in the USB HID code?

KY-040 TrinketHidCombo

I want to build an simple volume knob. The example "TrinketVolumeKnobPlus" is good for me.
Volume up and down work fine, but the mute button doesn't work.
In the code is one comment "remember that the switch is active-high".
The switch from KY-040 is active low.
What must I do to invert the code?

Warning about duplicate #define __SFR_OFFSET in TrinketMouse

I'm able to use TrinketMouse successfully, but when I compile I get an annoying warning:

In file included from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrvasm_includer.S:24:0:
/Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrv/usbdrvasm.S:18:0: warning: "__SFR_OFFSET" redefined
 #define __SFR_OFFSET 0      /* used by avr-libc's register definitions */
 ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/io.h:99:0,
                 from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/cmdline_defs.h:26,
                 from /Users/danielwong/Documents/Arduino/libraries/TrinketMouse/usbdrvasm_includer.S:22:
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/avr/include/avr/sfr_defs.h:141:0: note: this is the location of the previous definition
 #    define __SFR_OFFSET 0x20
 ^

I tried to solve this by commenting out line 18 in usbdrvasm.S, but that just broke everything. I also tried replacing that #define with #include <avr/sfr_defs.h> but that didn't do the trick either.

Obviously, this isn't the end of the world, but it would be nice to have clean builds.

Can't avoid driver issues in Windows 10

I'm using TrinketKeyboard and when I tested my code with prints throughout it works perfectly, but if I replace those prints with TrinketKeyboard.poll(); the driver will eventually drop out. Is there a better way to keep the device alive than just polling?

Errors when trying to use a 16Mhz board

D:\Docs\Arduino\libraries\TrinketHidCombo\usbdrv/asmcommon.inc: Assembler messages:
D:\Docs\Arduino\libraries\TrinketHidCombo\usbdrv/asmcommon.inc:98: Error: constant value required
D:\Docs\Arduino\libraries\TrinketHidCombo\usbdrv/asmcommon.inc:43: Error: invalid operands (ABS and UND sections) for <<' D:\Docs\Arduino\libraries\TrinketHidCombo\usbdrv/asmcommon.inc:59: Error: invalid operands (*ABS* and *UND* sections) for <<'
D:\Docs\Arduino\libraries\TrinketHidCombo\usbdrv/usbdrvasm16.inc:331: Error: invalid operands (ABS and UND sections) for `<<'
Compilation error: Error: 2 UNKNOWN: exit status 1

I get these errors when using a 16Mhz board (usbdrvasm16.inc from the official v-usb github). This doesn't happen on a 16.5Mhz board.

Any help solving these errors would be much appreciated.
Thanks!

TrinketHidCombo missing file

Fresh unzip won't compile because usbdrvasm16.inc: No such file or directory.

Error:
In file included from
/Arduino/libraries/TrinketHidCombo/usbdrvasm_includer.S:24:0:
/Arduino/libraries/TrinketHidCombo/usbdrv/usbdrvasm.S:384:34: fatal error: usbdrvasm16.inc: No such file or directory
compilation terminated.
exit status 1

Problem with USB BC1.2 port

I have written a simple keyboard program for the Trinket. It works on most computers, but not on a Chromebox with two types of USB ports:
USB 2.0: works OK
USB 2.0 with BC1.2 capability (additional charging current). In this case, the Trinket does not work (does not send keystroke) if it goes through the ChromeOS bootup routine. If, however, the Trinket is disconnected and then reconnected, it will work correctly until the next time the Chromebox is rebooted.

Code:

include <TrinketKeyboard.h>

define PIN_BUTTON_LETTER 0

//bfj 11-9-15

define KEYCODE_MOD_LEFT_CONTROL_ALT 0x05

//

define WAIT_TIME 250 //Time in milliseconds to wait between sending key presses

//Note: This is not a debounce. Customer wants keypress to be sent whenever key is held down, just not too //fast.

long nextSend; //When to send next keypress (last time sent plus WAIT_TIME)

void setup()
{
nextSend = millis(); //Ready for immedate send

// button pins as inputs
pinMode(PIN_BUTTON_LETTER, INPUT);

digitalWrite(PIN_BUTTON_LETTER, HIGH);
// Set button active-low

// start USB stuff
TrinketKeyboard.begin();
}

void loop()
{
TrinketKeyboard.poll();
// 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

if (digitalRead(PIN_BUTTON_LETTER) == LOW)
{
if (millis() > nextSend) //Time is up; ready to send
{
TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_CONTROL_ALT, KEYCODE_S);
TrinketKeyboard.pressKey(0, 0);
// this releases the key
nextSend = millis() + WAIT_TIME; //Reset timer
}
}

}

problems with TrinketKeyboard.print & TrinketKidCombo.print

In the code below, notice these lines:

  //test prints
  uint8_t buttonLEDstate = TrinketKeyboard.getLEDstate();
  TrinketKeyboard.print(buttonLEDstate,BIN); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.print("test"); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.println();

The buttonLEDstate only prints the first time. The subsequent 2 attempts at printing it do not work. There is an issue with the print and println commands. It is present with the TrinketHidCombo library too. Here is the output:

0, 
test, 

0, 
test, 

0, 
test, 

0, 
test, 

0, 
test, 

Here's the full code sample:

/*
readCapsLockState
-get the digispark to press the Windows shortcut key
Gabriel Staples
http://www.electricrcaircraftguy.com/
Written: 24 Dec. 2015 
Updated: 25 Dec. 2015
*/

//Includes
//For Trinket Keyboard & Mouse Combo functionality
//-Trinket Keyboard Help: https://learn.adafruit.com/trinket-usb-keyboard?view=all
//-NB: The poll function must be called at least once every 10 ms, or you must command a keystroke.
//--Otherwise, the computer may think that the device has stopped working, and give errors. Hence, DO NOT USE DELAY()!
//-Note: "HID" or "Hid" stands for "Human Interface Device." It is a well-defined USB standard. See here: https://en.wikipedia.org/wiki/Human_interface_device
#include <cmdline_defs.h>
#include <TrinketKeyboard.h>
#include <TrinketKeyboardC.h>
#include <usbconfig.h>

//#defines
#define KEY_CAPS_LOCK 0x39
#define TrinketHidReleaseKeys() TrinketKeyboard.pressKey(0,0)

//Global vars & consts
const byte LED_PIN = 1; //for my digisparks; other digisparks may use 0 as the LED pin

void setup()
{
  TrinketKeyboard.begin();
  pinMode(LED_PIN, OUTPUT);
}

void loop()
{
//  //blink LED; use fast blink to indicate error state/disconnect of digispark as HID device
//  static unsigned long t_start = millis();
//  static unsigned int blinkDelay = 1000; //ms
//  static boolean ledState = LOW;
//  if (millis() - t_start >= blinkDelay)
//  {
//    ledState = !ledState;
//    digitalWrite(LED_PIN,ledState);
//  }
//  if (TrinketKeyboard.isConnected()==true)
//    blinkDelay = 1000; //ms
//  else
//    blinkDelay = 50; //ms; fast blink to indicate error/disconnect of digispark as HID device

  //The poll function must be called at least once every 10 ms, or you must command a keystroke.
  //Otherwise, the computer may think that the device has stopped working, and give errors.
  TrinketKeyboard.poll();

////  TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_GUI,KEYCODE_R); //press the Windows Key + R (open "run" command box)
//  TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_GUI,0); //press the Windows Key
//  TrinketHidReleaseKeys();

  TrinketHidCompatibleDelay(1000);

  //test prints
  uint8_t buttonLEDstate = TrinketKeyboard.getLEDstate();
  TrinketKeyboard.print(buttonLEDstate,BIN); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.print("test"); TrinketKeyboard.print(", "); TrinketKeyboard.println(buttonLEDstate);
  TrinketKeyboard.println();

  //light up onboard LED when Caps Lock is on
  digitalWrite(LED_PIN, (TrinketKeyboard.getLEDstate()&KB_LED_CAPS)?HIGH:LOW);  

} //end of loop

//this is a USB-compatible delay, so that the 10ms max time between poll calls is not exceeded
void TrinketHidCompatibleDelay(unsigned int desiredDelay)
{
  unsigned long t_start = millis(); //ms
  while (millis()-t_start<desiredDelay)
  {
    TrinketKeyboard.poll();
  }
}

TrinketFakeUsbSerial doesn't work on Windows 7 64-bit

Windows doesn't accept the TrinketFakeUsbSerial driver, and instead installs the Trinket as an "Unknown device" on Windows 7 64-bit.

When connecting a device that is using a program with the TrinketFakeUsbSerial Arduino code, Windows does detect an "Unknown device", but the TrinketFakeUsbSerial driver can't be installed for it, even manually.

This process has been documented on Youtube by another guy: https://www.youtube.com/watch?v=Hih9O9Zzxs8

No way to SEND ___lock?

I can't seem to find the correct way to send a num/caps/scroll lock press. Checking the usage tables (PDF) that I remember someone pointing out, says that num/caps/scroll should be 0x53/0x39/0x47, but I can't seem to find a way to implement that in.

Help

Здравствуйте. Плата регулиет громкость звонка на андроид. а мне надо музыки. Код поправить можно?

Pro Trinket support?

Does this code work with the Pro Trinket? I'm specifically interested in the HID code.

errors in files

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

             from d:\users\user\Documents\Arduino\libraries\TrinketKeyboard\cmdline_defs.h:26,

             from d:\users\user\Documents\Arduino\libraries\TrinketKeyboard\usbdrvasm_includer.S:22:

d:\users\user\Documents\Arduino\libraries\TrinketKeyboard\usbconfig.h:392:33: error: operator '*' has no left operand

#define USB_INTR_PENDING GIFR

                             ^

d:\users\user\Documents\Arduino\libraries\TrinketKeyboard\usbdrv/usbdrvasm.S:73:5: note: in expansion of macro 'USB_INTR_PENDING'

#if USB_INTR_PENDING < 0x40 /* This is an I/O address, use in and out */

 ^

exit status 1
Error compiling for board Adafruit Trinket (ATtiny85 @ 8MHz).

How to trigger caps lock using trinket and trinketkeyboard.h

I want to make a program that checks if the caps lock is off, then if it is it turns caps lock on. But I can't see the output of getLEDstate() and it seems to not be working. is it that I am on Mac?
I tired this: digitalWrite(LED_CAPS, (TrinketKeyboard.getLEDstate()&KB_LED_CAPS)?HIGH:LOW);
but that doesn't do anything regardless if it is on or not.

does anyone know how to check the state and turn on the caps lock via code?

Compile Error: undefined reference to `usbCrc16Append'

I get the following error when I try to compile the TrinketKeyboardExample.

-------------------------
Arduino.mk Configuration:
- [AUTODETECTED]       CURRENT_OS = LINUX 
- [USER]               ARDMK_DIR = /home/piratenpete/.arduino/arduino_makefile 
- [USER]               ARDUINO_DIR = /home/piratenpete/Apps/arduino-1.0.5 
- [AUTODETECTED]       ARDUINO_VERSION = 105 
- [AUTODETECTED]       ARDUINO_PREFERENCES_PATH = /home/piratenpete/.arduino/preferences.txt 
- [AUTODETECTED]       ARDUINO_SKETCHBOOK = /home/piratenpete/Sketchbook (from arduino preferences file)
- [USER]               AVR_TOOLS_DIR = /usr 
- [COMPUTED]           ARDUINO_LIB_PATH = /home/piratenpete/Apps/arduino-1.0.5/libraries (from ARDUINO_DIR)
- [DEFAULT]            ARDUINO_CORE_PATH = /home/piratenpete/Apps/arduino-1.0.5/hardware/arduino/cores/arduino 
- [USER]               ALTERNATE_CORE = attiny 
- [COMPUTED]           ALTERNATE_CORE_PATH = /home/piratenpete/Sketchbook/hardware/attiny  (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE)
- [COMPUTED]           ARDUINO_VAR_PATH = /home/piratenpete/Sketchbook/hardware/attiny/variants (from ALTERNATE_CORE_PATH)
- [COMPUTED]           BOARDS_TXT = /home/piratenpete/Sketchbook/hardware/attiny/boards.txt (from ALTERNATE_CORE_PATH)
- [DEFAULT]            USER_LIB_PATH = /home/piratenpete/Sketchbook/libraries (in user sketchbook)
- [USER]               BOARD_TAG = trinket5 
- [COMPUTED]           OBJDIR = build-trinket5 (from BOARD_TAG)
- [ASSUMED]            MONITOR_BAUDRATE = 9600 
- [DEFAULT]            OPTIMIZATION_LEVEL = s 
- [DEFAULT]            MCU_FLAG_NAME = mmcu 
- [DEFAULT]            CFLAGS_STD = -std=gnu99 
- [AUTODETECTED]       Size utility: AVR-aware for enhanced output
-
-                      ARDUINO_LIBS =
- [USER]                 TrinketKeyboard
- [USER]                 SNESpad
- [COMPUTED]           BOOTLOADER_PARENT = /home/piratenpete/Apps/arduino-1.0.5/hardware/arduino/bootloaders (from ARDUINO_DIR)
-------------------------
/usr/bin/avr-gcc -mmcu=attiny85 -Wl,--gc-sections -Os    -o build-trinket5/TrinketKeyboardExample.elf build-trinket5/TrinketKeyboardExample.o build-trinket5/libcore.a  -lc -lm
build-trinket5/libcore.a(usbdrv_includer.o): In function `usbSetInterrupt':
usbdrv_includer.c:(.text.usbSetInterrupt+0x3c): undefined reference to `usbCrc16Append'
build-trinket5/libcore.a(usbdrv_includer.o): In function `usbPoll':
usbdrv_includer.c:(.text.usbPoll+0x1fc): undefined reference to `usbCrc16Append'
collect2: error: ld returned 1 exit status
make: *** [build-trinket5/TrinketKeyboardExample.elf] Error 1

If I try to compile it with the IDE I get the following error:

avr-gcc: error: unrecognized command line option ‘-assembler-with-cpp’

I am running avr-gcc version 4.7.2 and arduino 1.0.5 on Ubuntu 13.10

Alternative License?

Just wondering if the license could be changed to something more permissive, such as MIT or BSD, instead of the current LGPL license.

I was hope to re-use some of the constants and maybe the HID descriptor in the new HID over GATT API for my BLEPeripheral library which is under a MIT license.

Particularly:

@microbuilder suggested I raise an issue here.

My IDE shows, "Error compiling" when trying to verifiy my code.

I'm using the trinket to as a keyboard(trying to at least), but my problem is just with the IDE. I try to install the the library by sketch>inlcude library>add .zip then returns all clear.
Problem occures when i try to varifiey the code it, and it returns with this error message

"Arduino: 1.6.4 (Windows 7), Board: "Adafruit Trinket 8MHz"

Build options changed, rebuilding all

TrinketKeyboardExample.ino:6:29: fatal error: TrinketKeyboard.h: No such file or directory
compilation terminated.
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
"

My code from the library im trying to load.
"
/*
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!");
  }
}

"

Id really appreciate the help. Thanks!

pressKeys working & STRG + ALT + DEL how/why?

If i use TrinketHidCombo with as example "TrinketHidCombo.pressKey(KEYCODE_MOD_LEFT_SHIFT,KEYCODE_A,KEYCODE_B);" i get as expected result "AB" (working as left shift pressed with a + b) . But for what is "TrinketHidCombo.pressKeys" used. I can't get it working and maybe don't understand it full. I were glad if maybe someone can give me a working example for "TrinketHidCombo.pressKeys" with 3 or 4 list of keys. It says: "// presses a list of keys, do not exceed 5 keys". I did not find any example for that so i ask her for help.

The other question is why is "TrinketHidCombo.pressKey(0x50,KEYCODE_DELETE);" working as STRG + ALT + DEL? If i look at TrinketHidCombo.h 0x50 is Arrow Left (#define KEYCODE_ARROW_LEFT 0x50). Any info is welcome :)

Thanks and best regards.

Problem with USB BC1.2 port

I have written a simple keyboard program for the Trinket. It works on most computers, but not on a Chromebox with two types of USB ports:
USB 2.0: works OK
USB 2.0 with BC1.2 capability (additional charging current). In this case, the Trinket does not work (does not send keystroke) if it goes through the ChromeOS bootup routine. If, however, the Trinket is disconnected and then reconnected, it will work correctly until the next time the Chromebox is rebooted.

Code:

include <TrinketKeyboard.h>

define PIN_BUTTON_LETTER 0

//bfj 11-9-15

define KEYCODE_MOD_LEFT_CONTROL_ALT 0x05

//

define WAIT_TIME 250 //Time in milliseconds to wait between sending key presses

//Note: This is not a debounce. Customer wants keypress to be sent whenever key is held down, just not too //fast.

long nextSend; //When to send next keypress (last time sent plus WAIT_TIME)

void setup()
{
nextSend = millis(); //Ready for immedate send

// button pins as inputs
pinMode(PIN_BUTTON_LETTER, INPUT);

digitalWrite(PIN_BUTTON_LETTER, HIGH);
// Set button active-low

// start USB stuff
TrinketKeyboard.begin();
}

void loop()
{
TrinketKeyboard.poll();
// 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

if (digitalRead(PIN_BUTTON_LETTER) == LOW)
{
if (millis() > nextSend) //Time is up; ready to send
{
TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_CONTROL_ALT, KEYCODE_S);
TrinketKeyboard.pressKey(0, 0);
// this releases the key
nextSend = millis() + WAIT_TIME; //Reset timer
}
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.