Surferjoe86
New member
I'm a complete beginner making a replica spitfire flight stick and throttle quadrant.
I have the pots working.
But cant for the life of me get the joystick buttons working.
I have 7 joystick buttons in my code, they all light up in the game controller window.
The issue starts when I push a button 1 on the teensy, it blanks out joystick.button 2 and 4?
This is the only button seems to be working too. I have triple checked my wiring.
0-1-2-3-4-5-6 pins (on the ground side of the teensy 2.0) all go to micro switches. From the switches the wires then go to the centre ground on the Teensy (all pots use the same ground)
CODE:
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, 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(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
}
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(3)); //good
Joystick.Y(analogRead(1)); // good
Joystick.Z(analogRead(2)); // good
Joystick.sliderLeft(analogRead(0)); // good
Joystick.sliderRight(5);
if (digitalRead(0)== HIGH)
{ Joystick.button(1, digitalRead(0))
; } else {
Joystick.button(1, digitalRead(1))
; }
if (digitalRead(1)== HIGH)
{ Joystick.button(2, digitalRead(0))
; } else {
Joystick.button(2, digitalRead(1))
; }
if (digitalRead(2)== HIGH)
{ Joystick.button(3, digitalRead(0))
; } else {
Joystick.button(3, digitalRead(1))
; }
if (digitalRead(3)== HIGH)
{ Joystick.button(4, digitalRead(0))
; } else {
Joystick.button(4, digitalRead(1))
; }
if (digitalRead(4)== HIGH)
{ Joystick.button(5, digitalRead(0))
; } else {
Joystick.button(5, digitalRead(1))
; }
if (digitalRead(5)== HIGH)
{ Joystick.button(6, digitalRead(0))
; } else {
Joystick.button(6, digitalRead(1))
; }
if (digitalRead(6)== HIGH)
{ Joystick.button(7, digitalRead(0))
; } else {
Joystick.button(7, digitalRead(1))
; }
}
Any guidance would be greatly appreciated.
Joe
I have the pots working.
But cant for the life of me get the joystick buttons working.
I have 7 joystick buttons in my code, they all light up in the game controller window.
The issue starts when I push a button 1 on the teensy, it blanks out joystick.button 2 and 4?
This is the only button seems to be working too. I have triple checked my wiring.
0-1-2-3-4-5-6 pins (on the ground side of the teensy 2.0) all go to micro switches. From the switches the wires then go to the centre ground on the Teensy (all pots use the same ground)
CODE:
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, 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(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
}
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(3)); //good
Joystick.Y(analogRead(1)); // good
Joystick.Z(analogRead(2)); // good
Joystick.sliderLeft(analogRead(0)); // good
Joystick.sliderRight(5);
if (digitalRead(0)== HIGH)
{ Joystick.button(1, digitalRead(0))
; } else {
Joystick.button(1, digitalRead(1))
; }
if (digitalRead(1)== HIGH)
{ Joystick.button(2, digitalRead(0))
; } else {
Joystick.button(2, digitalRead(1))
; }
if (digitalRead(2)== HIGH)
{ Joystick.button(3, digitalRead(0))
; } else {
Joystick.button(3, digitalRead(1))
; }
if (digitalRead(3)== HIGH)
{ Joystick.button(4, digitalRead(0))
; } else {
Joystick.button(4, digitalRead(1))
; }
if (digitalRead(4)== HIGH)
{ Joystick.button(5, digitalRead(0))
; } else {
Joystick.button(5, digitalRead(1))
; }
if (digitalRead(5)== HIGH)
{ Joystick.button(6, digitalRead(0))
; } else {
Joystick.button(6, digitalRead(1))
; }
if (digitalRead(6)== HIGH)
{ Joystick.button(7, digitalRead(0))
; } else {
Joystick.button(7, digitalRead(1))
; }
}
Any guidance would be greatly appreciated.
Joe