Problems with Arduino Pro Micro sketch

Info on Project
Trying to make my Saitek Cyborg 3D Digital D15 joystick a usb joystick.
The program I hacked together from other peoples sketches, works does not work the right way.
Button press are set to keyboard press and not joystick buttons, have looked and have not found any list of how to code joystick buttons. Do not what to use A would rather have it joystick button1. ex I have the cap letter A having it set to Button1 would be better.
The joystick wiring should be in the sketch. All the wiring is what was in the joystick, just rewired to a board. In the picture the Pro Micro is under the green perf board. A cutout was made in the original board.
If you need any more please ask, and if I can will provide.

// (Starting point for what is in the sketch)
// USB 5 AXIS Controller
// Use with Arduino Leonardo or ProMicro.
// Install Joystick library

// (This is the starting point for buttons in this sketch)
// This code is a response to Angus' (from Maker's Muse) Macro Keyboard project
// (Making a custom macro keyboard with REAL arcade buttons - YouTube) where he asked for some help on
// making the Stream Deck script by Dave from Parts not Included
// (Building a DIY Stream Deck (Mini Macro Keyboard) - Parts Not Included)
// easier to understand.
// This code was featured in my video: My Take on a DiY Macro Hotkey Keyboard - YouTube
// The code is kept very light on purpose so hopefully everyone
// will be able to understand and alter it.
// include the library that is needed to simulate a keyboard:

// AMSTUDIO 2018
// YT amstudio - YouTube
// Wiring + Setup 5 AXIS ANALOG JOYSTICK GAME CONTROLLER - YouTube
// Copyright _ Non Commerical_ Not for Resale Creative Commons — Attribution-NonCommercial-NoDerivatives 4.0 International — CC BY-NC-ND 4.0

#include <Joystick.h>
#include <Keyboard.h>

// assign a pin number to each of the buttons:

// (color) is the color of the wire on the joystick
int Button_0 = 7; //Trigger (Brown) Ground (Black)
int Button_1 = 6; //Top Left (Pink)
int Button_2 = 5; //Top Middle (Yellow)
int Button_3 = 4; //Top Right (Green)
int Button_4 = 15; //Hat Up (Blue) Shares Ground (Black)
int Button_5 = 14; //Hat Right (Purple)
int Button_6 = 16; //Hat Down (Grey)
int Button_7 = 10; //Hat Left (White)
int Button_8 = 1; //F1 (Blue) Ground (Green)
int Button_9 = 0; //F2 (Brown)
int Button_10 = 2; //F3 (Orange)
int Button_11 = 3; //F4 (Orange Stripe)
int Button_12 = 8; //Bottom Left (Yellow) Ground (Thick Black)
//Bottom Right (Red) Reset for Arduino

// create an array of all buttons
// so they are easier to use:
int Buttons[] = {
Button_0, Button_1, Button_2,Button_3,Button_4,Button_5,Button_6,
Button_7, Button_8, Button_9,Button_10,Button_11,Button_12

};

Joystick_ Joystick;

const bool testAutoSendMode = false;

int XAxis_ = 0; //Pin A3 wire Orange 5V wire Green Ground Brown
int YAxis_ = 0; //Pin A2 wire Yellow 5V wire Grey Ground Brown
int ZAxis_ = 0; //Pin A1 wire Pink 5V wire Red Ground Brown
int Throttle_ = 0; //Pin A0 wire Blue 5V wire White Ground Brown

bool includeXAxis = true;
bool includeYAxis = true;
bool includeZAxis = true;
bool includeThrottle = true;

void setup()
{
Joystick.begin();

// figure out the amount of buttons used
// by dividing the total size of the array by
// the size of each element:
int buttonCount = sizeof(Buttons)/sizeof(int);

// make button pins an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
for (int i = 0; i < buttonCount; i++){
pinMode(Buttons*, INPUT_PULLUP);*

  • }*

  • // Start the keyboard:*

  • Keyboard.begin();*
    }

void loop(){

  • //BUTTON 0 --> Trigger*

  • if(digitalRead(Buttons[0])==LOW){*

  • Keyboard.press('N'); //press A*

  • Keyboard.release('N'); //release A*

  • delay(20); // Delay*

  • } *

  • //BUTTON 1 --> Top Left*

  • if(digitalRead(Buttons[1])==LOW){*

  • Keyboard.press('B'); //press B*

  • Keyboard.release('B'); //release B*

  • delay(20); // Delay*

  • } *

  • //BUTTON 2 --> Top Middle*

  • if(digitalRead(Buttons[2])==LOW){*

  • Keyboard.press('C'); //press C*

  • Keyboard.release('C'); //release C*

  • delay(20); // Delay*

  • } *

  • //BUTTON 3 --> Top Right*

  • if(digitalRead(Buttons[3])==LOW){*

  • Keyboard.press('O'); //press D*

  • Keyboard.release('O'); //release D*

  • delay(20); // Delay*

  • } *

  • //BUTTON 4 --> Hat Up*

  • if(digitalRead(Buttons[4])==LOW){*

  • Keyboard.press('W'); //press E*

  • Keyboard.release('W'); //release E*

  • delay(20); // Delay*

  • } *

  • //BUTTON 5 --> Hat Right*

  • if(digitalRead(Buttons[5])==LOW){*

  • Keyboard.press('D'); //press F*

  • Keyboard.release('D'); //release F*

  • delay(20); // Delay*

  • } *

  • //BUTTON 6 --> Hat Down*

  • if(digitalRead(Buttons[6])==LOW){*

  • Keyboard.press('S'); //press G*

  • Keyboard.release('S'); //release G*

  • delay(20); // Delay*

  • } *

  • //BUTTON 7 --> Hat Left*

  • if(digitalRead(Buttons[7])==LOW){*

  • Keyboard.press('A'); //press H*

  • Keyboard.release('A'); //release H*

  • delay(20); // Delay*

  • } *

  • //BUTTON 8 --> F1*

  • if(digitalRead(Buttons[8])==LOW){*

  • Keyboard.press('I'); //press I*

  • Keyboard.release('I'); //release I*

  • delay(20); // Delay*

  • } *

  • //BUTTON 9 --> F2*

  • if(digitalRead(Buttons[9])==LOW){*

  • Keyboard.press('J'); //press J*

  • Keyboard.release('J'); //release J*

  • delay(20); // Delay*

  • } *

  • //BUTTON 10 --> F3*

  • if(digitalRead(Buttons[10])==LOW){*

  • Keyboard.press('K'); //press K*

  • Keyboard.release('K'); //release K*

  • delay(20); // Delay*

  • } *

  • //BUTTON 11 --> F4*

  • if(digitalRead(Buttons[11])==LOW){*

  • Keyboard.press('L'); //press L*

  • Keyboard.release('L'); //release L*

  • delay(20); // Delay*

  • } *

  • //BUTTON 11 --> Bottom Left (Bottom Right is used as a rest for the Arduino)*

  • if(digitalRead(Buttons[12])==LOW){*

  • Keyboard.press('M'); //press M*

  • Keyboard.release('M'); //release M*

  • delay(30); // Delay*

  • } *

  • XAxis_ = analogRead(A3);*

  • XAxis_ = map(XAxis_,1023,0,255,0);*

  • Joystick.setXAxis(XAxis_);*

  • YAxis_ = analogRead(A2);*

  • YAxis_ = map(YAxis_,1023,0,255,0);*

  • Joystick.setYAxis(YAxis_);*

  • ZAxis_ = analogRead(A1);*

  • ZAxis_ = map(ZAxis_,1023,0,255,0); *

  • Joystick.setZAxis(ZAxis_);*

  • Throttle_ = analogRead(A0);*

  • Throttle_ = map(Throttle_,1023,0,255,0); *

  • Joystick.setThrottle(Throttle_); *

delay (20);
}
//AMSTUDIO Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.


Saitek 3D Digital.jpg
Finished_Joystick.ino (5.58 KB)

Saitek 3D Digital.jpg

//o// what great comments to follow ion your code, it is self explanatory!!! It is as good as the schematic you posted! You did some rewiring, post the Schematic as you have wired it, not a frizzy thing and links to all hardware components. After reading all of your post I have no idea of what you are doing. You might also tell us how it is supposed to work and what it does not do.

Arduino Pro Micro is under the green perf board.

Looking for help with the code. The x axis y axis z axis and throttle work as there should.

  • //BUTTON 0 --> Trigger*
  • if(digitalRead(Buttons[0])==LOW){*
  • Keyboard.press('N'); //press A*
  • Keyboard.release('N'); //release A*
  • delay(20); // Delay*
  • } *

The problem is with this code above this is one of 13 that are the same and I would like something better.
All the buttons are mapped to keyboard would like it to be mapped to joystick.
I do not what N to be pressed would like to have joystick button1 pressed
joystick button1 is an example because I do not know what the names of buttons on joysticks are called on a factory joystick.
When I go to calibrate the joystick non of the buttons show up under calibration in windows 10.
This is an example of what I am looking for.

* //BUTTON 0 --> Trigger*
* if(digitalRead(Buttons[0])==LOW){*
* Joystick.press('Button1'); //press A*
* Joystick.release('Button1'); //release A*
* delay(20); // Delay*
* } *

This does not work but it is the only way I can enplane it.

As for wiring diagram do not have one just info in the code as to which wire goes to which pin.

Was looking in the joystick.ccp in " ArduinoJoystickLibrary-Master

void Joystick_::setButton(uint8_t button, uint8_t value)
{
if (value == 0)
{
releaseButton(button);
}
else
{
pressButton(button);
}
}
void Joystick_::pressButton(uint8_t button)
{
if (button >= _buttonCount) return;

int index = button / 8;
int bit = button % 8;

This looks like it is giving names to buttons, but there is no list of names.
This library is using coding math to give out the names of buttons.

Was wondering if anyone knows of a way to remove the keyboard.h library from the sketch and make it work.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.