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
psp stick to teensy code
- wermy
- Site Admin
- Posts: 1346
- Joined: Tue May 03, 2016 8:51 pm
- Has thanked: 620 times
- Been thanked: 1322 times
- Contact:
Re: psp stick to teensy code
Can you post some code?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
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
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.
then i tried combinding the code with slightly modified version of yours
im just not sure how to combine them correctly as ive never coded before. thanks for the fast reply wermy
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);
}
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);
}
}
}
Re: psp stick to teensy code
sorry forgot to use the replywermy wrote:Can you post some code?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
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?
Who is online
Users browsing this forum: No registered users and 1 guest