Hi All,
Just bought myself a Teensy 3.1, was wanting to make a nifty custom HID for Guild Wars 2 (MMO)
The device I want to create has two separate boxes, 9 buttons and a thumbstick (playstation 2 variant with select click) on both boxes (18 buttons and two thumbsticks), as well as adding an additional 3 foot pedals for obvious reasons (jump, dodge, and jump+dodge)
Now each thing is supposed to do something different as in a key stroke on the keyboard. (now if it is hard to emulate both keyboard and mouse at the same time, I can easily remedy this issue with xpadder if I make the joystick just visible with all the buttons in Windows)
joy one=w,a,s,d,
joy two=rightclick+mouse movement (this'll be a tricky)
+technically 23 buttons (18 buttons+3 foot pedals+2 select buttons on thumbsticks)[buttons will not have resistors but will need code on input pullup]
My question is, how would I go about coding this devil? and also Looking for a decent trapezoidal enclosure for that slanted finger rest for button press.
I know with the rest of the keys/buttons it will be simple to code, now I just need help on the thumbstick portion, since I cannot find anything that remotely resembles examples throughout searching this past hour on 20+ different sites/forums, and figured someone here might have an idea on how to code the left thumbstick as 'w' 'a' 's' 'd' for each direction, and setting up the right thumbstick as a right_mouseclick + mouse movement accordingly. Any help would be graciously accepted. thanks for your time.
figured someone here might have an idea on how to code the left thumbstick as 'w' 'a' 's' 'd' for each direction,
So, when the left joystick is pushed all the way forward and centered, you want to send 'w', 'a', 's', and 'd'. And, when the left joystick is centered and pushed all the way left, you want to send 'w', 'a', 's', and 'd'. Ans, when the joystick is pulled all the way back and pushed all the way right, you want to send 'w', 'a', 's', and 'd'.
Reading the stick values is easy. Deciding what to do with the X and Y values is the challenge. Does a movement at all cause a character to be output? Does moving the stick back from the forward limit cause a 's' to be output? Or should 'w' be output whenever the Y value increases? Or, should 'w' be output only when the stick is in the forward-most, centered position?
What should be output when the stick is pushed forward and right, to the limits?
Generating the output is easy once you can define the requirements. For the left stick, anyway. I'm not sure that you can generate mouse output the way you describe.
// joystick input pins
int joy1X = 0;
int joy1Y = 1;
int joy2X = 2;
int joy2Y = 3;
// joystick 1 x & y values
int joy1X_value;
int joy1Y_value;
// joystick 1 movement deltas
int deltaX;
int deltaY;
// joystick 2 x & y values
int joy2X_value;
int joy2Y_value;
// deadzone value for joystick 2
int deadzone = 50;
// for led
int ledPin = 6;
boolean ledOn = false;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin,LOW);
}
void loop()
{
// joystick 1 - mouse
joy1X_value = analogRead(joy1X);
joy1Y_value = analogRead(joy1Y);
// convert x & y into values from -20 - 20
deltaX = (-511 + (joy1X_value)) /25;
deltaY = (-511 + (joy1Y_value)) /25;
// move the mouse by the delta values
Mouse.move(deltaX,deltaY);
// joystick 2 keyboard
// convert to -511 - 512
joy2X_value = -511 + analogRead(joy2X);
joy2Y_value = -511 + analogRead(joy2Y);
// if x movement greater than deadzone
if (joy2X_value > deadzone)
{
// move right = key D down
Keyboard.press('d');
}
// if x movement less than negative deadzone
else if (joy2X_value < -deadzone)
{
// move left = key A down
Keyboard.press('a');
}
else
{
// in the deadzone range so both keys up
Keyboard.release('a');
Keyboard.release('d');
}
// if y movement greater than deadzone
if (joy2Y_value > deadzone)
{
// move down = key S down
Keyboard.press('s');
}
// if x movement less than negative deadzone
else if (joy2Y_value < -deadzone)
{
// move up = key W down
Keyboard.press('w');
}
else
{
// in the deadzone range so both keys up
Keyboard.release('s');
Keyboard.release('w');
}
// short delay so code runs at 40 times per second
delay(25);
// toggle the led
ledOn = !ledOn;
digitalWrite(ledPin, ledOn);
}
Thanks to Les/Pointy from Teensy forums for this blueprint for what I need, but still looking for adding something that toggles a held right click, or have it as a constant as I move the right stick in any direction.