Advice on tweensy 2.0 joystick

Hey everyone

I'm trying to convert an Amiga joystick in to a USB joystick adapter, using a teensy 2.0. I'd read online that it was possible, however the guides are a little old and the end result is a device with 32 buttons.

I realise as a newbie, I'm not asking anything that hasn't been asked before. But does anyone know if there is a more up to date guide? The joystick I'm converting is a pretty simple open close switch setup with just a single fire button.

Alternatively if anyone can recommend where I might be best posing this question to get advice. I'd be very grateful :slight_smile:

As I said I'm relatively new to these tiny boards and only bought the teensy in the hopes it would solve a problem.

Show us the code you have so far. What does it actually do? What would you like it to do different?

/*

Simple Game Controller Code
For use with the Teensy++ 2.0 and MMA7361 Accelerometer

Version 1.00

(C)Pointy 2014

The code expects the following...

11 buttons wired between gnd and the Teens++ 2.0 pins 0-5 & 7-11
2 voltages on pins A0-A1 to represent the joystick X,Y position.

The MMA7361 is wired as follows...

VCC - 3.3V
GND - AGND
ZOUT - (Not used)
YOUT - A3 (RY Axis)
XOUT - A2 (RX Axis)
SLP - Tied High

*/

int ledPin = 6;
boolean ledOn = false;

void setup() {
// set pin modes
for(int i=0; i <13; i++){
// ignore pin 6
if (i != 6)
pinMode(i,INPUT_PULLUP);
}
pinMode(ledPin, OUTPUT);
// set manual send
Gamepad.useManualSend(true);
// set led off
digitalWrite(ledPin,LOW);
}

void loop() {
// MMA7361 doesn't output full range to we need to tweak values
// read rx analog value
int rx = analogRead(2);
// double range
rx = (rx - 511) * 2 + 511;
// cap result
if (rx > 1023)
rx=1023;
if (rx < 0)
rx = 0;
// invert rx
rx=abs(1023-rx);
// read rY analog value
int ry = analogRead(3);
// double range
ry = (ry - 511) * 2 + 511;
// cap result
if (ry > 1023)
ry=1023;
if (ry < 0)
ry = 0;

// read analog inputs for x & y axis
Gamepad.X(analogRead(0));
Gamepad.Y(analogRead(1));
Gamepad.RX(rx);
Gamepad.RY(ry);

// read the digital inputs and set the buttons
for(int i=0; i <12; i++){
// buttons are 1 to 11, digital pins are 0 to 11 ignoring pin 6
if (i <= 6)
Gamepad.button(i+1, !digitalRead(i)); // 1st 6 buttons
else
Gamepad.button(i, !digitalRead(i));// last 5 buttons
}

// a brief delay, so this runs 100 times per second
delay(10);

Gamepad.send_now();

// toggle our led
ledOn = !ledOn;
digitalWrite(ledPin, ledOn);
}

I might have actually found a better alternative :slight_smile:
http://robertbyam.com/code/simplegamepad.html
But I won't know till I give it a shot. I'm still wet behind the ears when it comes to using these boards, but I hope I can get it working. Would really make my week, if I could get the teensy to appear as a USB joypad.