Hey all,
I’ve been trying to get arduino micro (or any other AVR board with an ATmega32u4 controller) to work with the new unity input system.
Arduino code with joystick library. It has 1 stick and 2 buttons.
#include <Joystick.h>
//Define and Allocate Input Pins to memorable names
#define joyX A0
#define joyY A1
#define joyButton1 6
#define joyButton2 9
//Initializing Axis as Integers, at a 0 default value
int xAxis_ = 0;
int yAxis_ = 0;
//Setting up Buttons
//Updating a static variable gives greater stability than reading directly from the digital pin.
//Giving Default Values to the Buttons for later use
int lastButton1State = 0;
int lastButton2State = 0;
Joystick_ Joystick(0x12, JOYSTICK_TYPE_JOYSTICK, 2, 0, true, true, false, false, false, false, false, false, false, false, false);
//Set Auto Send State
//Enables Auto Sending, allowing the controller to send information to the HID system, rather than waiting to be asked.
const bool initAutoSendState = true;
void setup() {
pinMode(joyButton1, INPUT_PULLUP);
pinMode(joyButton2, INPUT_PULLUP);
//Start Joystick - Needed to start the Joystick function libary
Joystick.begin();
}
void loop() {
xAxis_ = analogRead(joyX);
xAxis_ = map(xAxis_, 0, 1023, 0, 255);
Joystick.setXAxis(xAxis_);
yAxis_ = analogRead(joyY);
yAxis_ = map(yAxis_, 0, 1023, 0, 255);
Joystick.setYAxis(yAxis_);
int currentButton1State = !digitalRead(joyButton1);
if (currentButton1State != lastButton1State) {
Joystick.setButton(0, currentButton1State);
lastButton1State = currentButton1State;
}
int currentButton2State = !digitalRead(joyButton2);
if (currentButton2State != lastButton2State) {
Joystick.setButton(1, currentButton2State);
lastButton2State = currentButton2State;
}
delay(10);
}
This all works fine and windows recognizes the stick and buttons.
However, working in unity I seem to be having trouble getting it to recognize the controller and the inputs. The default its reading is all out of place. For some reason the value sticks on (-0,71, 0,70). When I move you see the values change though.
Moreover, you can see when listening for input on the input action mapping tool. that it can only detect up and left on the stick.
I have tried learning new things from this thread . However, it seems I’m with a different issue. There isn’t any C# code to peel through as this issue seems to be someplace else. But just to verify, in the character creation screen it is also shown that the controller tries to always move up and to the left. Is there maybe another way to debug outside of Unity to test if my joystick is working correctly? Or is there a way to callibrate it in Unity so to negate the already bad input? Thank you for reading and possible your help in advance.