psp stick to teensy code

Hardware-related questions that don't fit into any of the specialized hardware categories go here.
Post Reply
User avatar
LilJosh
Posts: 9
Joined: Thu May 19, 2016 10:57 pm
Has thanked: 1 time
Been thanked: 1 time

psp stick to teensy code

Post by LilJosh » Tue Jun 07, 2016 1:41 am

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

User avatar
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

Post by wermy » Tue Jun 07, 2016 7:54 am

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?
ImageImageImageImage

User avatar
LilJosh
Posts: 9
Joined: Thu May 19, 2016 10:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: psp stick to teensy code

Post by LilJosh » Tue Jun 07, 2016 2:54 pm

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 :)

User avatar
LilJosh
Posts: 9
Joined: Thu May 19, 2016 10:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: psp stick to teensy code

Post by LilJosh » Tue Jun 07, 2016 11:39 pm

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

Fixmylife
Posts: 28
Joined: Tue May 02, 2017 11:43 pm
Has thanked: 1 time
Been thanked: 3 times

Re: psp stick to teensy code

Post by Fixmylife » Tue May 02, 2017 11:46 pm

Hey man im really new to all of this , was wondering if you got through your issue.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest