[NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Various user-contributed guides for hardware-related things
Post Reply
User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by vnman » Thu Apr 20, 2017 8:09 am

correia5022 wrote:
Tue Apr 18, 2017 7:38 pm
Hey guys

One quick question. After uploading the code, my arduino leonardo stays with the same name. Shouldnt be like a controller or io device or something like that?
Now is just connecting the buttons to the pins and its done?
yes. It should show up under "Devices and Printers" as "Arduino Leonardo". If you selected "Sparkfun...." as the board in Arduino IDE then Windows will display "IO USB..."

Before connecting to the pi you can check if it is show up in Windows as "Controller".

dcherof
Posts: 5
Joined: Wed Feb 08, 2017 9:08 pm

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by dcherof » Thu Apr 20, 2017 11:31 am

vnman wrote:
Thu Apr 20, 2017 1:29 am
dcherof wrote:
Tue Apr 18, 2017 4:11 pm
I don't think that version is offered for Mac users sadly. has anyone used this code successfully using a mac version of the arduino software, and if so what did you do?
The link for download is also on the first page -

https://www.arduino.cc/en/Main/OldSoftw ... ases#1.0.x
They only allow download of 1.0.5 and 1.0.6 not 1.0.5r2. Im sure Im missing something right under my nose but I've followed the guide line by line and it doesnt seem to work on either 1.0.5 or 1.0.6.

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by vnman » Fri Apr 21, 2017 8:14 am

dcherof wrote:
Thu Apr 20, 2017 11:31 am
vnman wrote:
Thu Apr 20, 2017 1:29 am
dcherof wrote:
Tue Apr 18, 2017 4:11 pm
I don't think that version is offered for Mac users sadly. has anyone used this code successfully using a mac version of the arduino software, and if so what did you do?
The link for download is also on the first page -

https://www.arduino.cc/en/Main/OldSoftw ... ases#1.0.x
They only allow download of 1.0.5 and 1.0.6 not 1.0.5r2. Im sure Im missing something right under my nose but I've followed the guide line by line and it doesnt seem to work on either 1.0.5 or 1.0.6.
My bad ...I check the google code web site and you are right 1.0.5r2 is only available for Windows...

dcherof
Posts: 5
Joined: Wed Feb 08, 2017 9:08 pm

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by dcherof » Sat Apr 22, 2017 12:10 pm

vnman wrote:
Fri Apr 21, 2017 8:14 am
dcherof wrote:
Thu Apr 20, 2017 11:31 am
vnman wrote:
Thu Apr 20, 2017 1:29 am


The link for download is also on the first page -

https://www.arduino.cc/en/Main/OldSoftw ... ases#1.0.x
They only allow download of 1.0.5 and 1.0.6 not 1.0.5r2. Im sure Im missing something right under my nose but I've followed the guide line by line and it doesnt seem to work on either 1.0.5 or 1.0.6.
My bad ...I check the google code web site and you are right 1.0.5r2 is only available for Windows...
any thoughts on how to modify the code to work on a different IDE?

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by vnman » Sat Apr 22, 2017 7:56 pm

I am working on it...

So far I have the buttons working...

User avatar
vnman
Posts: 147
Joined: Tue Jun 21, 2016 5:21 am
Has thanked: 5 times
Been thanked: 34 times

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by vnman » Sun Apr 23, 2017 3:59 am

OK.

I modified the code to work with the new version of Arduino IDE.

I have not done thorough test of analog sticks (yet), since my only PSP stick seems to be defect....Order on the way....

Code: Select all

//
// Using Library https://github.com/MHeironimus/ArduinoJoystickLibrary
//

#include <Joystick.h>

// If you have only one analog stick, set this to 1,
// If you have 2, set this to 2,
// If you do not have any at all, set this to 0.
// In theory, 4 are possible, but this script is limited to 2.
int AnalogSticks = 2;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
  14, 0,                  // Button Count, Hat Switch Count
  true, true, false,     // X and Y, but no Z Axis
  true, true, false,   // Rx, Ry, no Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

// Analog stick input pins, invert, and deadzone:
int deadzone = 4; // Values under 5 will return 0
int x1Pin = A0;
int y1Pin = A1;
int x2Pin = A2;
int y2Pin = A3;
int InvertX1 = 0;
int InvertY1 = 0;
int InvertX2 = 0;
int InvertY2 = 0;

// Button input pins. Please take care not to use a value twice!:
// If you do NOT use a button listed here, please assign it to a FREE, UNSUSED pin !!THIS IS IMPORTANT!!
int PinA = 1;
int PinB = 0;
int PinX = 2;
int PinY = 3;
int PinStart = 4;
int PinSelect = 5;
int PinDPadUp = 6;
int PinDPadDown = 7;
int PinDPadLeft = 8;
int PinDPadRight = 9;
int PinL1 = 10;
int PinL2 = 16;
int PinR1 = 14;
int PinR2 = 15;

// Button mapping (1-14). Please take care not to use a value twice!:
// If you do NOT use a button in the input map, set it to 0 here.
int A = 0;
int B = 1;
int X = 2;
int Y = 3;
int Start = 4;
int Select = 5;
int DPadUp = 6;
int DPadDown = 7;
int DPadLeft = 8;
int DPadRight = 9;
int L1 = 10;
int L2 = 11;
int R1 = 12;
int R2 = 13;

// Variable declarations for analog sticks
int x1Zero, y1Zero;
int x1Value, y1Value;
int x2Zero, y2Zero;
int x2Value, y2Value;
int x1Min, x1Max;
int y1Min, y1Max;
int x2Min, x2Max;
int y2Min, y2Max;
int x1F1, x1F2;
int y1F1, y1F2;
int x2F1, x2F2;
int y2F1, y2F2;

void tAnalogSticks(){
  // Read analog sticks and respect the deadzone value
  x1Value = analogRead(x1Pin) - x1Zero;
  y1Value = analogRead(y1Pin) - y1Zero;
  x2Value = analogRead(x2Pin) - x2Zero;
  y2Value = analogRead(y2Pin) - y2Zero;
  
  if(abs(x1Value) < deadzone) {
    x1Value = 0;
  }
  if(abs(y1Value) < deadzone) {
    y1Value = 0;
  }
  if(abs(x2Value) < deadzone) {
    x2Value = 0;
  }
  if(abs(y2Value) < deadzone) {
    y2Value = 0;
  }

// Autocalibration of analog sticks (by Helder + wermy)
  if (x1Value > 0 && x1Value > x1Max) {
    x1Max = x1Value;
  } else if (x1Value < 0 && x1Value < x1Min) {
    x1Min = x1Value;
  }

  if (y1Value > 0 && y1Value > y1Max) {
    y1Max = y1Value;
  } else if (y1Value < 0 && y1Value < y1Min) {
    y1Min = y1Value;
  }

  float x1sMax = abs(x1Max);
  if (x1Value < 0) {
    x1sMax = abs(x1Min);
  }

  float y1sMax = abs(y1Max);
  if (y1Value < 0) {
    y1sMax = abs(y1Min);
  }
  
  if (x2Value > 0 && x2Value > x2Max) {
    x2Max = x2Value;
  } else if (x2Value < 0 && x2Value < x2Min) {
    x2Min = x2Value;
  }

  if (y2Value > 0 && y2Value > y2Max) {
    y2Max = y2Value;
  } else if (y2Value < 0 && y2Value < y2Min) {
    y2Min = y2Value;
  }

  float x2sMax = abs(x2Max);
  if (x2Value < 0) {
    x2sMax = abs(x2Min);
  }

  float y2sMax = abs(y2Max);
  if (y2Value < 0) {
    y2sMax = abs(y2Min);
  }
  int16_t x1Final = (((float)x1Value / x1sMax)*127);
  int16_t y1Final = (((float)y1Value / y1sMax)*127);
  int16_t x2Final = (((float)x2Value / x2sMax)*127);
  int16_t y2Final = (((float)y2Value / y2sMax)*127);

  // Check if Axis need to be inverted, and if yes, do so
  if (InvertX1 == 0) {
    x1F1 = 127;
    x1F2 = -127;
  }
  else {
    x1F1 = -127;
    x1F2 = 127;
  }
  if (InvertY1 == 0) {
    y1F1 = 127;
    y1F2 = -127;
  }
  else {
    y1F1 = -127;
    y1F2 = 127;
  }
  if (InvertX2 == 0) {
    x2F1 = 127;
    x2F2 = -127;
  }
  else {
    x2F1 = -127;
    x2F2 = 127;
  }
  if (InvertY2 == 0) {
    y2F1 = 127;
    y2F2 = -127;
  }
  else {
    y2F1 = -127;
    y2F2 = 127;
  }
  
  // Check how many analog sticks have been specified (0, 1, 2)
  // and disable (center) any that aren't used.
  if (AnalogSticks != 1 && AnalogSticks != 2) {
    x1Final = 0;
    y1Final = 0;
    x2Final = 0;
    y2Final = 0;
  }
  if (AnalogSticks == 1) {
    x2Final = 0;
    y2Final = 0;
  }
  
  Joystick.setXAxis(map(x1Final, x1F1, x1F2, 0, 255));
  Joystick.setYAxis(map(y1Final, y1F1, y1F2, 0, 255));
  Joystick.setRxAxis(map(x2Final, x2F1, x2F2, 0, 255));
  Joystick.setRyAxis(map(y2Final, y2F1, y2F2, 0, 255));
}

void tButtonStates(){
// Button states are checked with digitalRead
  // For a common ground PCB, it checks for a LOW state
  // If it detects one on any button pin, it will return a corresponding
  // value counting from 1-8192 and later on these values are added together,
  // else the value is 0
  if (digitalRead(PinA) == LOW) {
    Joystick.setButton(A, 1);
  }
  else {
    Joystick.setButton(A, 0);
  }
  if (digitalRead(PinB) == LOW) {
    Joystick.setButton(B, 1);
  }
  else {
    Joystick.setButton(B, 0);
  }
  if (digitalRead(PinX) == LOW) {
    Joystick.setButton(X, 1);
  }
  else {
    Joystick.setButton(X, 0);
  }
  if (digitalRead(PinY) == LOW) {
    Joystick.setButton(Y, 1);
  }
  else {
    Joystick.setButton(Y, 0);
  }
  if (digitalRead(PinStart) == LOW) {
    Joystick.setButton(Start,1);
  }
  else {
    Joystick.setButton(Start,0);
  }
  if (digitalRead(PinSelect) == LOW) {
    Joystick.setButton(Select,1);
  }
  else {
    Joystick.setButton(Select,0);
  }
  if (digitalRead(PinDPadUp) == LOW) {
    Joystick.setButton(DPadUp,1);
  }
  else {
    Joystick.setButton(DPadUp,0);
  }
  if (digitalRead(PinDPadDown) == LOW) {
    Joystick.setButton(DPadDown,1);
  }
  else {
    Joystick.setButton(DPadDown,0);
  }
  if (digitalRead(PinDPadLeft) == LOW) {
    Joystick.setButton(DPadLeft,1);
  }
  else {
    Joystick.setButton(DPadLeft,0);
  }
  if (digitalRead(PinDPadRight) == LOW) {
    Joystick.setButton(DPadRight,1);
  }
  else {
    Joystick.setButton(DPadRight,0);
  }
  if (digitalRead(PinL1) == LOW) {
    Joystick.setButton(L1,1);
  }
  else {
    Joystick.setButton(L1,0);
  }
  if (digitalRead(PinL2) == LOW) {
    Joystick.setButton(L2,1);
  }
  else {
    Joystick.setButton(L2,0);
  }
  if (digitalRead(PinR1) == LOW) {
    Joystick.setButton(R1,1);
  }
  else {
    Joystick.setButton(R1,0);
  }
  if (digitalRead(PinR2) == LOW) {
    Joystick.setButton(R2,1);
  }
  else {
    Joystick.setButton(R2,0);
}
}

void setup(){
  // Declare buttons as inputs
  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  
  // Declare specified pins as analog inputs for analog sticks
  pinMode(x1Pin, INPUT);
  pinMode(y1Pin, INPUT);
  pinMode(x2Pin, INPUT);
  pinMode(y2Pin, INPUT);
  
  // Measure 'neutral' position for analog sticks
  x1Zero = analogRead(x1Pin);
  y1Zero = analogRead(y1Pin);
  x2Zero = analogRead(x2Pin);
  y2Zero = analogRead(y2Pin);
      
  Joystick.setXAxisRange(-127, 127);
  Joystick.setYAxisRange(-127, 127);
  Joystick.setRxAxisRange(-127, 127);
  Joystick.setRxAxisRange(-127, 127);
  Joystick.setXAxis(0);
  Joystick.setYAxis(0);
  Joystick.setRxAxis(0);
  Joystick.setRyAxis(0);

  Joystick.begin();
}

void loop(){
  tButtonStates();
  tAnalogSticks();
}

User avatar
dbak85
Posts: 40
Joined: Thu Mar 09, 2017 2:04 am
Has thanked: 14 times
Been thanked: 19 times

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by dbak85 » Sun Apr 23, 2017 1:03 pm

Hi Sota

I got everything working on a teensy with some minor changes to your code. works great.

The only thing I am having trouble with is I did not realize that I had glued my sticks in place at a angle. They are rotated 45degrees.

I have been trying to wrap my head around how you rotate the joysticks. Could you show how you did it?

dcherof
Posts: 5
Joined: Wed Feb 08, 2017 9:08 pm

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by dcherof » Mon Apr 24, 2017 9:37 pm

vnman wrote:
Sun Apr 23, 2017 3:59 am
OK.

I modified the code to work with the new version of Arduino IDE.

I have not done thorough test of analog sticks (yet), since my only PSP stick seems to be defect....Order on the way....

Code: Select all

//
// Using Library https://github.com/MHeironimus/ArduinoJoystickLibrary
//

#include <Joystick.h>

// If you have only one analog stick, set this to 1,
// If you have 2, set this to 2,
// If you do not have any at all, set this to 0.
// In theory, 4 are possible, but this script is limited to 2.
int AnalogSticks = 2;

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
  14, 0,                  // Button Count, Hat Switch Count
  true, true, false,     // X and Y, but no Z Axis
  true, true, false,   // Rx, Ry, no Rz
  false, false,          // No rudder or throttle
  false, false, false);  // No accelerator, brake, or steering

// Analog stick input pins, invert, and deadzone:
int deadzone = 4; // Values under 5 will return 0
int x1Pin = A0;
int y1Pin = A1;
int x2Pin = A2;
int y2Pin = A3;
int InvertX1 = 0;
int InvertY1 = 0;
int InvertX2 = 0;
int InvertY2 = 0;

// Button input pins. Please take care not to use a value twice!:
// If you do NOT use a button listed here, please assign it to a FREE, UNSUSED pin !!THIS IS IMPORTANT!!
int PinA = 1;
int PinB = 0;
int PinX = 2;
int PinY = 3;
int PinStart = 4;
int PinSelect = 5;
int PinDPadUp = 6;
int PinDPadDown = 7;
int PinDPadLeft = 8;
int PinDPadRight = 9;
int PinL1 = 10;
int PinL2 = 16;
int PinR1 = 14;
int PinR2 = 15;

// Button mapping (1-14). Please take care not to use a value twice!:
// If you do NOT use a button in the input map, set it to 0 here.
int A = 0;
int B = 1;
int X = 2;
int Y = 3;
int Start = 4;
int Select = 5;
int DPadUp = 6;
int DPadDown = 7;
int DPadLeft = 8;
int DPadRight = 9;
int L1 = 10;
int L2 = 11;
int R1 = 12;
int R2 = 13;

// Variable declarations for analog sticks
int x1Zero, y1Zero;
int x1Value, y1Value;
int x2Zero, y2Zero;
int x2Value, y2Value;
int x1Min, x1Max;
int y1Min, y1Max;
int x2Min, x2Max;
int y2Min, y2Max;
int x1F1, x1F2;
int y1F1, y1F2;
int x2F1, x2F2;
int y2F1, y2F2;

void tAnalogSticks(){
  // Read analog sticks and respect the deadzone value
  x1Value = analogRead(x1Pin) - x1Zero;
  y1Value = analogRead(y1Pin) - y1Zero;
  x2Value = analogRead(x2Pin) - x2Zero;
  y2Value = analogRead(y2Pin) - y2Zero;
  
  if(abs(x1Value) < deadzone) {
    x1Value = 0;
  }
  if(abs(y1Value) < deadzone) {
    y1Value = 0;
  }
  if(abs(x2Value) < deadzone) {
    x2Value = 0;
  }
  if(abs(y2Value) < deadzone) {
    y2Value = 0;
  }

// Autocalibration of analog sticks (by Helder + wermy)
  if (x1Value > 0 && x1Value > x1Max) {
    x1Max = x1Value;
  } else if (x1Value < 0 && x1Value < x1Min) {
    x1Min = x1Value;
  }

  if (y1Value > 0 && y1Value > y1Max) {
    y1Max = y1Value;
  } else if (y1Value < 0 && y1Value < y1Min) {
    y1Min = y1Value;
  }

  float x1sMax = abs(x1Max);
  if (x1Value < 0) {
    x1sMax = abs(x1Min);
  }

  float y1sMax = abs(y1Max);
  if (y1Value < 0) {
    y1sMax = abs(y1Min);
  }
  
  if (x2Value > 0 && x2Value > x2Max) {
    x2Max = x2Value;
  } else if (x2Value < 0 && x2Value < x2Min) {
    x2Min = x2Value;
  }

  if (y2Value > 0 && y2Value > y2Max) {
    y2Max = y2Value;
  } else if (y2Value < 0 && y2Value < y2Min) {
    y2Min = y2Value;
  }

  float x2sMax = abs(x2Max);
  if (x2Value < 0) {
    x2sMax = abs(x2Min);
  }

  float y2sMax = abs(y2Max);
  if (y2Value < 0) {
    y2sMax = abs(y2Min);
  }
  int16_t x1Final = (((float)x1Value / x1sMax)*127);
  int16_t y1Final = (((float)y1Value / y1sMax)*127);
  int16_t x2Final = (((float)x2Value / x2sMax)*127);
  int16_t y2Final = (((float)y2Value / y2sMax)*127);

  // Check if Axis need to be inverted, and if yes, do so
  if (InvertX1 == 0) {
    x1F1 = 127;
    x1F2 = -127;
  }
  else {
    x1F1 = -127;
    x1F2 = 127;
  }
  if (InvertY1 == 0) {
    y1F1 = 127;
    y1F2 = -127;
  }
  else {
    y1F1 = -127;
    y1F2 = 127;
  }
  if (InvertX2 == 0) {
    x2F1 = 127;
    x2F2 = -127;
  }
  else {
    x2F1 = -127;
    x2F2 = 127;
  }
  if (InvertY2 == 0) {
    y2F1 = 127;
    y2F2 = -127;
  }
  else {
    y2F1 = -127;
    y2F2 = 127;
  }
  
  // Check how many analog sticks have been specified (0, 1, 2)
  // and disable (center) any that aren't used.
  if (AnalogSticks != 1 && AnalogSticks != 2) {
    x1Final = 0;
    y1Final = 0;
    x2Final = 0;
    y2Final = 0;
  }
  if (AnalogSticks == 1) {
    x2Final = 0;
    y2Final = 0;
  }
  
  Joystick.setXAxis(map(x1Final, x1F1, x1F2, 0, 255));
  Joystick.setYAxis(map(y1Final, y1F1, y1F2, 0, 255));
  Joystick.setRxAxis(map(x2Final, x2F1, x2F2, 0, 255));
  Joystick.setRyAxis(map(y2Final, y2F1, y2F2, 0, 255));
}

void tButtonStates(){
// Button states are checked with digitalRead
  // For a common ground PCB, it checks for a LOW state
  // If it detects one on any button pin, it will return a corresponding
  // value counting from 1-8192 and later on these values are added together,
  // else the value is 0
  if (digitalRead(PinA) == LOW) {
    Joystick.setButton(A, 1);
  }
  else {
    Joystick.setButton(A, 0);
  }
  if (digitalRead(PinB) == LOW) {
    Joystick.setButton(B, 1);
  }
  else {
    Joystick.setButton(B, 0);
  }
  if (digitalRead(PinX) == LOW) {
    Joystick.setButton(X, 1);
  }
  else {
    Joystick.setButton(X, 0);
  }
  if (digitalRead(PinY) == LOW) {
    Joystick.setButton(Y, 1);
  }
  else {
    Joystick.setButton(Y, 0);
  }
  if (digitalRead(PinStart) == LOW) {
    Joystick.setButton(Start,1);
  }
  else {
    Joystick.setButton(Start,0);
  }
  if (digitalRead(PinSelect) == LOW) {
    Joystick.setButton(Select,1);
  }
  else {
    Joystick.setButton(Select,0);
  }
  if (digitalRead(PinDPadUp) == LOW) {
    Joystick.setButton(DPadUp,1);
  }
  else {
    Joystick.setButton(DPadUp,0);
  }
  if (digitalRead(PinDPadDown) == LOW) {
    Joystick.setButton(DPadDown,1);
  }
  else {
    Joystick.setButton(DPadDown,0);
  }
  if (digitalRead(PinDPadLeft) == LOW) {
    Joystick.setButton(DPadLeft,1);
  }
  else {
    Joystick.setButton(DPadLeft,0);
  }
  if (digitalRead(PinDPadRight) == LOW) {
    Joystick.setButton(DPadRight,1);
  }
  else {
    Joystick.setButton(DPadRight,0);
  }
  if (digitalRead(PinL1) == LOW) {
    Joystick.setButton(L1,1);
  }
  else {
    Joystick.setButton(L1,0);
  }
  if (digitalRead(PinL2) == LOW) {
    Joystick.setButton(L2,1);
  }
  else {
    Joystick.setButton(L2,0);
  }
  if (digitalRead(PinR1) == LOW) {
    Joystick.setButton(R1,1);
  }
  else {
    Joystick.setButton(R1,0);
  }
  if (digitalRead(PinR2) == LOW) {
    Joystick.setButton(R2,1);
  }
  else {
    Joystick.setButton(R2,0);
}
}

void setup(){
  // Declare buttons as inputs
  pinMode(1, INPUT_PULLUP);
  pinMode(0, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  
  // Declare specified pins as analog inputs for analog sticks
  pinMode(x1Pin, INPUT);
  pinMode(y1Pin, INPUT);
  pinMode(x2Pin, INPUT);
  pinMode(y2Pin, INPUT);
  
  // Measure 'neutral' position for analog sticks
  x1Zero = analogRead(x1Pin);
  y1Zero = analogRead(y1Pin);
  x2Zero = analogRead(x2Pin);
  y2Zero = analogRead(y2Pin);
      
  Joystick.setXAxisRange(-127, 127);
  Joystick.setYAxisRange(-127, 127);
  Joystick.setRxAxisRange(-127, 127);
  Joystick.setRxAxisRange(-127, 127);
  Joystick.setXAxis(0);
  Joystick.setYAxis(0);
  Joystick.setRxAxis(0);
  Joystick.setRyAxis(0);

  Joystick.begin();
}

void loop(){
  tButtonStates();
  tAnalogSticks();
}
Thank you so much for the help! My prized paperweight will have new life. Ill let you know how it goes on my end

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

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by Fixmylife » Fri May 26, 2017 6:15 pm

Hey you wouldn't happen to know what would be the pin out put for this kind of psp joy stick
Attachments
-50PC-LOT-Wholesale-Price-For-3D-Analog-Rocker-Buttons-3D-font-b-Joystick-b-font.jpg
-50PC-LOT-Wholesale-Price-For-3D-Analog-Rocker-Buttons-3D-font-b-Joystick-b-font.jpg (68.15 KiB) Viewed 52331 times

onilx
Posts: 6
Joined: Sat May 27, 2017 8:50 am
Location: Tokyo, Japan
Been thanked: 3 times
Contact:

Re: [NEW VERSION] Sota's 14 buttons + optional up to 2 analog sticks guide for a Leonardo Pro Micro (Teensy alternative)

Post by onilx » Sat May 27, 2017 8:56 am

I've succeeded at making a usb controller that shows up on my Mac but when i plug it into my raspberry Pi 3, in either raspbian or retropie, it's not seen. Did you go through any other steps to get your USB controller to work?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest