Hello everyone,
I am attempting to create a game controller for a Nintendo Entertainment System emulator by using buttons and a joystick for inputs. Directions on a joystick and buttons being pressed corresponds to a certain key on the keyboard using the Keyboard.write function.
However, when I attempt to press a button or use the joystick, a completely different key is written. For example, I use the code
if(digitalRead(ButtonA) == LOW)
{
Keyboard.write("n");
}
Instead of typing "n" it types"="
However, if I set that same exact line of code to a different key, such as "t", then it still writes "="
What is even weirder, is that if I have another button I have coded with the exact same code other than the button being used and the key I want it to type, say "b", it will write "?"
And again, if I change the key being typed it still types "?"
The same applies with my other buttons except they write "c" and "a"
Then I have my joystick which actually has 2 problems
- No matter what direction the joystick is in it will still be typing a key even though it is only set to above an X value of 800.
- Regardless, the key I put in "Keyboard.write" is different again. In this case, I ask it to type "d" and it types "g", and it still types "g" even if I change the "d". Just like the buttons, the other 3 directions on the joystick are set to their own keys, regardless of what I set them to.
What do I do to fix my Keyboard.write issue? It has never been like this before. In fact, I made a controller using the exact same parts and code a few months ago and it worked fine but I accidentally deleted the code. This is truly bizarre and I don't know why it is happening. In addition, if anyone can help me with why the joystick is constantly typing then that would be awesome.
I am using an Arduino Leonardo on a School Windows 7 PC
Here is my code
Joystick_sample.ino (1.27 KB)