bwalls1996
New member
Hi everyone, im using a Teensy 3.2 to make a custom USB game controller using a psp style joystick and tactile momentary buttons. I've got the joystick being read, I'm just having trouble mapping it. I'm using the following code and have tried plugging in different values but nothing seems to be working correctly.
The second problem I'm having is with the buttons. I have the pins set to INPUT_PULLUP and i understand the active low meaning the button is HIGH when pressed and LOW when released, but what this translates to on my controller is the buttons constantly being pressed until they receive a physical press, then the controller reads them as released. Its pretty much working backwards. And when I take the PULLUP code out, the buttons aren't picked up at all. Im pretty much just looking for someone to point me in the right direction on where to find and put the correct values for the joystick, and some insight on my button situation. Any help would be greatly appreciated and I thank you before hand for your time.
Im currently running the basic example code for the Teensy Joystick, as followed:
Code:
Joystick.X(map(analogRead(0),170, 853, 1023, 0));
Joystick.Y(map(analogRead(1),170, 853, 0, 1023));
Im currently running the basic example code for the Teensy Joystick, as followed:
Code:
/* Basic USB Joystick Example
Teensy becomes a USB joystick
You must select Joystick from the "Tools > USB Type" menu
Pushbuttons should be connected to digital pins 0 and 1.
Wire each button between the digital pin and ground.
Potentiometers should be connected to analog inputs 0 to 1.
This example code is in the public domain.
*/
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
}
void loop() {
// read analog inputs and set X-Y position
Joystick.X(analogRead(0));
Joystick.Y(analogRead(1));
// read the digital inputs and set the buttons
Joystick.button(1, digitalRead(0));
Joystick.button(2, digitalRead(1));
// a brief delay, so this runs 20 times per second
delay(50);
}