You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
#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)
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:
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)
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)
Using
TrinketHidCompatibleDelay(2000)
at the beginning of setup() pretty much guarantees a successful startup with good prints.Here's some of its outputs:
Why? Is there a better way? Is this a bug somewhere in the USB HID code?
The text was updated successfully, but these errors were encountered: