Hello, First post I am sorry for anything that may not be up to spec.
I am trying to build a USB HID modular switch board for someone with mobility issues. My code is getting hung up somewhere causing my computer to recognize only one key press at a time.
I have each individual switch working in the way that I want them to, thanks to other posts and info on this forum, however I cannot read from more than one pin at a time. I am under the understanding that USB HID should support six simultaneous presses at the same time, but I can only get one to show up. So for example, if I am using WASD motion, I can either go straight OR right, not forward towards the right.
I know that it must be something with the code getting hung up on the the pin that is connected, but I don't know enough about how to keep it from getting hung up. So may of the things I have tried over the past couple days just bug out my code. And, so many of the HID tutorials either deal with getting a single button working or jump into keyboard matrices which I am not using.
Any advice would be amazing. Thank you.
- Bud
Teensy LC - Arduino 1.6.8
void setup() {
// make pin x an input and turn on the
// pullup resistor so it goes low unless
// connected to ground:
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
//When Pin 0 is connected to Ground
while (digitalRead(0) == LOW)
{
Keyboard.press(KEY_1);
delay (100); // debounce
while (digitalRead(0) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_1); // Release Key
} // Pin 0 No Longer connected to Ground
//When Pin 1 is connected to Ground
while (digitalRead(1) == LOW)
{
Keyboard.press(KEY_3);
delay (100); // debounce
while (digitalRead(1) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_3); // Release Key
} // Pin 1 No Longer connected to Ground
//When Pin 2 is connected to Ground
while (digitalRead(2) == LOW)
{
Keyboard.press(char(0x20));
delay (100); // debounce
while (digitalRead(2) == LOW)
{ } // Wait for Release
Keyboard.release(char(0x20)); // Release Key
} // Pin 2 No Longer connected to Ground
//When Pin 3 is connected to Ground
while (digitalRead(3) == LOW)
{
Keyboard.press(char(10));
delay (100); // debounce
while (digitalRead(3) == LOW)
{ } // Wait for Release
Keyboard.release(char(10)); // Release Key
} // Pin 3 No Longer connected to Ground
//When Pin 4 is connected to Ground
while (digitalRead(4) == LOW)
{
Keyboard.press(KEY_W);
delay (100); // debounce
while (digitalRead(4) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_W); // Release Key
} // Pin 4 No Longer connected to Ground
//When Pin 5 is connected to Ground
while (digitalRead(5) == LOW)
{
Keyboard.press(KEY_S);
delay (100); // debounce
while (digitalRead(5) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_S); // Release Key
} // Pin 5 No Longer connected to Ground
//When Pin 6 is connected to Ground
while (digitalRead(6) == LOW)
{
Keyboard.press(KEY_A);
delay (100); // debounce
while (digitalRead(6) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_A); // Release Key
} // Pin 6 No Longer connected to Ground
//When Pin 7 is connected to Ground
while (digitalRead(7) == LOW)
{
Keyboard.press(KEY_D);
delay (100); // debounce
while (digitalRead(7) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_D); // Release Key
} // Pin 7 No Longer connected to Ground
//When Pin 8 is connected to Ground
while (digitalRead(8) == LOW)
{
Keyboard.press(KEY_UP_ARROW);
delay (100); // debounce
while (digitalRead(8) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_UP_ARROW); // Release Key
} // Pin 8 No Longer connected to Ground
//When Pin 9 is connected to Ground
while (digitalRead(9) == LOW)
{
Keyboard.press(KEY_DOWN_ARROW);
delay (100); // debounce
while (digitalRead(9) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_DOWN_ARROW); // Release Key
} // Pin 9 No Longer connected to Ground
//When Pin 10 is connected to Ground
if (digitalRead(10) == LOW)
{
Keyboard.press(KEY_LEFT_ARROW);
delay (100); // debounce
while (digitalRead(10) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_LEFT_ARROW); // Release Key
} // Pin 10 No Longer connected to Ground
//When Pin 11 is connected to Ground
while (digitalRead(11) == LOW)
{
Keyboard.press(KEY_RIGHT_ARROW);
delay (100); // debounce
while (digitalRead(11) == LOW)
{ } // Wait for Release
Keyboard.release(KEY_RIGHT_ARROW); // Release Key
} // Pin 11 No Longer connected to Ground
//When Pin 12 is connected to Ground
while (digitalRead(12) == LOW)
{
Keyboard.press(char(0x1B));
delay (100); // debounce
while (digitalRead(12) == LOW)
{ } // Wait for Release
Keyboard.release(char(0x1B)); // Release Key
} // Pin 12 No Longer connected to Ground
}
