IntrepidChuck
New member
Hello, Newbie here. I'm working on a game controller and am having some issues with the joystick values reading high. Both X and Y axis are reading about 866-878 at resting state. Max goes to 1023, while min stops at 166. It happens for both axis, individually. Not sure if I did some wiring wrong or am missing some code to set the resting values.
Using the Teensy LC with the Phoneix PS2 Joystick Module.
Any assistance is greatly appreciated. Thank you.
Using the Teensy LC with the Phoneix PS2 Joystick Module.
Any assistance is greatly appreciated. Thank you.
Code:
const int numButtons = 13; // 16 for Teensy, 32 for Teensy++
void setup() {
Joystick.useManualSend(true);
for (int i=0; i<numButtons; i++) {
pinMode(i, INPUT_PULLUP);
}
}
byte allButtons[numButtons];
byte prevButtons[numButtons];
int angle=0;
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(A5));
Joystick.Y(analogRead(A6));
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[i] = 0;
} else {
// when a pin reads low, the button is connecting to ground.
allButtons[i] = 1;
}
Joystick.button(i + 1, allButtons[i]);
}
// 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[i] != prevButtons[i]) anyChange = true;
prevButtons[i] = allButtons[i];
}
delay(50);
}
Last edited: