Page 1 of 1
psp stick to teensy code
Posted: Tue Jun 07, 2016 1:41 am
by LilJosh
I've been working on trying to get several traces of code found around the forms but have had no luck. I have used the sample code from pjrc and the joystick works, but the main issue is getting it to work as the joystick, keyboard events or button presses simultaneously. Any help would greatly be appreciated.
http://i.imgur.com/19dl0Bo.jpg
Re: psp stick to teensy code
Posted: Tue Jun 07, 2016 7:54 am
by wermy
LilJosh wrote:I've been working on trying to get several traces of code found around the forms but have had no luck. I have used the sample code from pjrc and the joystick works, but the main issue is getting it to work as the joystick, keyboard events or button presses simultaneously. Any help would greatly be appreciated.
http://i.imgur.com/19dl0Bo.jpg
Can you post some code?
You say the joystick works, are you determining that by logging out values or something?
Are you selecting "Serial + Keyboard + Mouse + Joystick" for "USB Type" in the Tools menu in the Arduino IDE?
Re: psp stick to teensy code
Posted: Tue Jun 07, 2016 2:54 pm
by LilJosh
i loaded up this code to my teesny 3.2 fist to test the joystick under joy.cpl in windows , i believe i tried using "Serial + Keyboard + Mouse + Joystick" but didnt have any success. will try again tonight after work.
Code: Select all
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
}
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(0));
Joystick.Y(analogRead(1));
// a brief delay, so this runs 20 times per second
delay(50);
}
then i tried combinding the code with slightly modified version of yours
Code: Select all
#include <Bounce.h>
#define NUM_KEYS 14
struct Key {
char keycode;
Bounce* bounce;
};
Key keys[NUM_KEYS];
Key key(char keycode, int pin) {
Key *ret = new Key;
ret->keycode = keycode;
ret->bounce = new Bounce(pin, 10);
pinMode(pin, INPUT_PULLUP);
return *ret;
}
void setupKeys() {
keys[0] = key('a', 0);
keys[1] = key('w', 1);
keys[2] = key('s', 2);
keys[3] = key('d', 3);
keys[4] = key('p', 4);
keys[5] = key('l', 5);
keys[6] = key('o', 6);
keys[7] = key('k', 7);
keys[8] = key('x', 8);
keys[9] = key('z', 9);
keys[10] = key('q',10);
keys[11] = key('e',11);
keys[12] = key('n',12);
keys[13] = key('m',13);
keys[14] = key('u',14);
}
void setup() {
setupKeys();
Keyboard.begin();
// pinMode(0, INPUT_PULLUP);
}
void loop() {
for (int i = 0; i < NUM_KEYS; i++) {
keys[i].bounce->update();
if (keys[i].bounce->fallingEdge()) {
Keyboard.press(keys[i].keycode);
} else if (keys[i].bounce->risingEdge()) {
Keyboard.release(keys[i].keycode);
}
}
}
im just not sure how to combine them correctly as ive never coded before. thanks for the fast reply wermy

Re: psp stick to teensy code
Posted: Tue Jun 07, 2016 11:39 pm
by LilJosh
wermy wrote:LilJosh wrote:I've been working on trying to get several traces of code found around the forms but have had no luck. I have used the sample code from pjrc and the joystick works, but the main issue is getting it to work as the joystick, keyboard events or button presses simultaneously. Any help would greatly be appreciated.
http://i.imgur.com/19dl0Bo.jpg
Can you post some code?
You say the joystick works, are you determining that by logging out values or something?
Are you selecting "Serial + Keyboard + Mouse + Joystick" for "USB Type" in the Tools menu in the Arduino IDE?
sorry forgot to use the reply
Re: psp stick to teensy code
Posted: Tue May 02, 2017 11:46 pm
by Fixmylife
Hey man im really new to all of this , was wondering if you got through your issue.