xbox 360 control

So I have a project where I want to use an Xbox 360 controller to control 2 separate DC motors, one with the left joystick and one with the right. All I need is to have it read the Y component and adjust motor power accordingly. I have figured out how to get this to work with transistors, but obviously the motors wont go backwards like that, so I implemented an H-bridge. I only had one so I just tested it with the left joystick and one DC motor. The issue i am having is that as soon as I move the joystick the controller disconnects from the receiver and the serial monitor just displays the first coordinate read. I have no idea why. Code is below.

#include<XBOXRECV.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

USB Usb;
XBOXRECV Xbox(&Usb);

int powerL;

void setup() {
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
Serial.begin(9600);
#if !defined(MIPSEL)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
}

void loop() {
Usb.Task();
if (Xbox.XboxReceiverConnected)
{
if(Xbox.Xbox360Connected)
{
if(Xbox.getAnalogHat(LeftHatY) >7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatY) >7500 || Xbox.getAnalogHat(RightHatY) < -7500)
{
if(Xbox.getAnalogHat(LeftHatY) >7500 || Xbox.getAnalogHat(LeftHatY) < -7500 )
{
if(Xbox.getAnalogHat(LeftHatY) >7500)
{
Serial.print(F("LeftHatY: "));
Serial.println(Xbox.getAnalogHat(LeftHatY));
digitalWrite(3,LOW);
digitalWrite(2,HIGH);
powerL = map(Xbox.getAnalogHat(LeftHatY), 7500 , 32767 , 0 , 255);
analogWrite(10,powerL);
}
if (Xbox.getAnalogHat(LeftHatY) < -7500)
{
Serial.print(F("LeftHatY: "));
Serial.println(Xbox.getAnalogHat(LeftHatY));
digitalWrite(3,HIGH);
digitalWrite(2,LOW);
powerL = map(Xbox.getAnalogHat(LeftHatY), -7500 , -32767 , 0 , 255);
analogWrite(10,powerL);
}
}
if(Xbox.getAnalogHat(RightHatY) >7500 || Xbox.getAnalogHat(RightHatY) < -7500)
{
Serial.print(F("RightHatY: "));
Serial.println(Xbox.getAnalogHat(RightHatY));
}
}
}
}
}

I had a similar problem with controlling LEDs with a potentiometer. I had a bunch of if statements like that in the loop and the arduino would get hung up on certain constraints and in my case the Arduino would stop receiving signal from my potentiometer. I created functions and only called one of the functions in the loop. the rest of the functions created a loop using else statements so it was like a double loop if that make sense. Here is a link to my forum post. This may help it may not but it seems like a similar problem. (download the sketch to see what i mean).

https://forum.arduino.cc/index.php?topic=355348.0

willk3808:
The issue i am having is that as soon as I move the joystick the controller disconnects from the receiver and the serial monitor just displays the first coordinate read. I have no idea why.

Does this occur only when the motor is connected?

Do you think the connection issue coincides with the analogWrite to the h-bridge?

My bet is you have a power supply issue.