# Advice on tweensy 2.0 joystick

**URL:** <https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150>\
**Category:** General Guidance\
**Created:** [April 28, 2018, 11:35pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150 "2018-04-28T23:35:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haemogoblin](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@Haemogoblin](https://forum.arduino.cc/u/Haemogoblin)\
**Post date:** [April 28, 2018, 11:35pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/1 "2018-04-28T23:35:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Haemogoblin](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@Haemogoblin](https://forum.arduino.cc/u/Haemogoblin)\
**Post date:** [April 29, 2018, 8:28pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/2 "2018-04-29T20:28:43Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![MorganS](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/morgans/32/218718_2.png) [@MorganS](https://forum.arduino.cc/u/MorganS)\
**Post date:** [April 29, 2018, 10:30pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/3 "2018-04-29T22:30:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Haemogoblin](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@Haemogoblin](https://forum.arduino.cc/u/Haemogoblin)\
**Post date:** [April 30, 2018, 9:13pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/4 "2018-04-30T21:13:47Z")

</div>

/\*

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);  
}

---

<div class="post-metadata">

**Author:** ![Haemogoblin](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@Haemogoblin](https://forum.arduino.cc/u/Haemogoblin)\
**Post date:** [April 30, 2018, 9:31pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/5 "2018-04-30T21:31:35Z")

</div>

I might have actually found a better alternative 🙂  
[http://robertbyam.com/code/simplegamepad.html](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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 6:33pm UTC](https://forum.arduino.cc/t/advice-on-tweensy-2-0-joystick/523150/6 "2021-05-05T18:33:41Z")

</div>


