 #include <sx1509_library.h>
 #include <Adafruit_NeoPixel.h>
 
-//Not sure if these are needed, but the LED isn't working so might as well
 #ifdef __AVR__
 #include <avr/power.h>
 #endif

			aleft=255;
			pleft=aleft;
			pright=0;
			// nleft=180;
		} else if (right==0) {
			aright=255;
			pright=aright;
			pleft=0;
			// nright=180;
		}
		motor_SetOutputs(nleft,aleft,nright,aright );
		Serial.print(pleft);
		Serial.print(" ");
		Serial.print(pright);

		Serial.print(aleft);
		Serial.print(" ");
		Serial.print(aright);
		Serial.println(" ");
	}
}

void motor_SetOutputs(int apina, int apinb, int bpina, int bpinb) { 
	// Each motor has 2 parts, reverse output and forward output
	// PinA=reverse pin
	// PinB=forward pin
	sx1509.pwm(motor_APinA, apina);
	sx1509.pwm(motor_APinB, apinb);
	sx1509.pwm(motor_BPinA, bpina);
	sx1509.pwm(motor_BPinB, bpinb);
}

void setLEDColour(int r, int g, int b) {
	for (int i = 0; i < 1; i++) { 
		// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255	
		pixels.setPixelColor(i, pixels.Color(r, g, b));
		pixels.show();  // sends updated color to hardware
	}
}

void server_SendGood() {
	server.send (200, "text/html", "recieved"); // Tell the client that their request went through
}

int getArg(String arg) {
	return atoi(server.arg(arg).c_str()); // Cast the string arguments to integer and return
}

void server_HandleRoot(){
	Serial.println("Handling Root\n");
	// Get arguments from request, default=0
	int apina=getArg("apina");
	int apinb=getArg("apinb");
	int bpina=getArg("bpina");
	int bpinb=getArg("bpinb");
	int r=getArg("r");
	int g=getArg("g");
	int b=getArg("b");
	int freq=getArg("freq");
	int duration=getArg("dur");
	int restart=getArg("restart");

	robot_Mode=getArg("mode"); // Set robot mode
	if (freq==0) { // Stop tone generation
		noTone(tone_Pin);
	} else if (duration!=0) { // Set tone to play for set time in milliseconds
		tone(tone_Pin,freq,duration);
		delay(duration);
		noTone(tone_Pin);
	} else { // Play tone 'forever'
		tone(tone_Pin,freq,1000000);
	}
 
	// Set motor outputs to received values
	motor_SetOutputs(apina,apinb,bpina,bpinb);
	// Set LED to received values
	setLEDColour(r,g,b);

	// Build response displaying given variables
	String response = "<h1>Update 9-16</h1><h2>Arguments:</h2><p>";
	for (uint8_t i=0; i<server.args(); i++)
		response+="\t"+server.argName(i)+":\t"+server.arg(i)+"\n";
