I'm trying to program a Teensy 3.1 as keyboard, and I'm using an example from https://www.pjrc.com/teensy/td_keyboard.html.
int count = 0;
void setup() { } // no setup needed
void loop() {
Keyboard.print("Hello World ");
Keyboard.println(count);
count = count + 1;
delay(5000);
}
I successfully uploaded the script to the Teensy and the script execution starts immediately. The problem is that after that if I unplug the Teensy and plug it for a second time, nothing is happening. Does someone know what I am doing wrong?
You're not doing anything wrong; this is expected behavior. As the documentation states:
You may notice "Hello World 0" does not appear. The PC takes a brief time to detect the presence of a new USB device, but this program begins running immediately. If you use Keyboard.print() before the PC finishes the detection process (called "enumeration" in USB lingo), Keyboard.print() does nothing.
The only remedy stated is:
A delay() can be added in setup(), if necessary.
Suggest you put a nice long delay in setup()
to give your PC time to recognize the keyboard.