Perhaps start with File > Examples > Teensy > USB_Joystick > Buttons.
Thanks for advice. I'm not good with codes as never done anything with them at all.
What I actually did was I used > Examples > Teensy > USB_Joystick > Complete which gave me 16 buttons and 6 axis. managed to get it down to 2 axis by simply removing from the code remaining ones. Also managed to change number of buttons by simply replacing number of them in code to 18. There was also something called hatswitch which was causing my xbox controller emulator to show buttons going in a loop one after another... Quick search thru code took me to some value stating "loop" and by quick deduction it made me believe that this is what causing it - deleted entire function and my joystick finally works as it should!!!!!!!!!!!!!
There's only one thing that I'm trying to sort out now but I'm failing big time. I'm not asking for someone to do the job for me as I'm really trying to understand what's what but with no knowledge and experience I'm struggling badly.
Button No.14 is showing to be constantly ON - no shortcuts or incorrectly connected wires.
Here's the code and I seriously can't find reason why is it happening. As I said I have removed few lines from oryginal one and reasigned analog pins but Button No.14 had same status even on example code before i touched it...
/* Complete USB Joystick Example
Teensy becomes a USB joystick with 16 or 32 buttons and 6 axis input
You must select Joystick from the "Tools > USB Type" menu
Pushbuttons should be connected between the digital pins and ground.
Potentiometers should be connected to analog inputs 0 to 5.
This example code is in the public domain.
*/
// Configure the number of buttons. Be careful not
// to use a pin for both a digital button and analog
// axis. The pullup resistor will interfere with
// the analog voltage.
const int numButtons = 18; // 16 for Teensy, 32 for Teensy++
void setup() {
// you can print to the serial monitor while the joystick is active!
Serial.begin(9600);
// configure the joystick to manual send mode. This gives precise
// control over when the computer receives updates, but it does
// require you to manually call Joystick.send_now().
Joystick.useManualSend(true);
for (int i=0; i<numButtons; i++) {
pinMode(i, INPUT_PULLUP);
}
Serial.println("Begin Complete Joystick Test");
}
byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;
void loop() {
// read 6 analog inputs and use them for the joystick axis
Joystick.X(analogRead(4));
Joystick.Y(analogRead(5));
// read digital pins and use them for the buttons
for (int i=0; i<numButtons; i++) {
if (digitalRead(i)) {
// when a pin reads high, the button is not pressed
// the pullup resistor creates the "on" signal
allButtons
= 0;
} else {
// when a pin reads low, the button is connecting to ground.
allButtons = 1;
}
Joystick.button(i + 1, allButtons);
}
// Because setup configured the Joystick manual send,
// the computer does not see any of the changes yet.
// This send_now() transmits everything all at once.
Joystick.send_now();
// check to see if any button changed since last time
boolean anyChange = false;
for (int i=0; i<numButtons; i++) {
if (allButtons != prevButtons) anyChange = true;
prevButtons = allButtons;
}
// if any button changed, print them to the serial monitor
if (anyChange) {
Serial.print("Buttons: ");
for (int i=0; i<numButtons; i++) {
Serial.print(allButtons, DEC);
}
Serial.println();
}
// a brief delay, so this runs "only" 200 times per second
delay(5);
}
Can You see anything in that code that would make that Button no 14 being ON ? Is it because it's connected to digital pin No13 which is a LED one by default?
Thank You