//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,
/*
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();
}
}