#include <Arduino.h>
#line 1 "E:\\Mixly999\\testArduino\\testArduino.ino"
#line 1 "E:\\Mixly999\\testArduino\\testArduino.ino"
#include<Emakefun_MotorDriver.h>
Emakefun_MotorDriver mMotorDriver = Emakefun_MotorDriver(0x60,5);

#include<PS2X_lib.h>
PS2X *ps2x;

volatile float leftright;

#line 9 "E:\\Mixly999\\testArduino\\testArduino.ino"
void aim();
#line 33 "E:\\Mixly999\\testArduino\\testArduino.ino"
void servoset();
#line 37 "E:\\Mixly999\\testArduino\\testArduino.ino"
void setup();
#line 50 "E:\\Mixly999\\testArduino\\testArduino.ino"
void loop();
#line 9 "E:\\Mixly999\\testArduino\\testArduino.ino"
void aim() {
  if (ps2x->Button(32768)) {
    leftright = leftright + 1;
    Serial.print(ps2x->Button(32768));
    Serial.print("hello");
    Serial.println(round(leftright));

  } else if (ps2x->Button(8192)) {
    leftright = leftright - 1;
    Serial.print(ps2x->Button(8192));
    Serial.print("hello");
    Serial.println(round(leftright));
  }
  if (leftright >= 180) {
    leftright = 180;

  } else if (leftright <= 0) {
    leftright = 0;
  }
  servoset();
}

Emakefun_Servo *servo6 = mMotorDriver.getServo(6);

void servoset() {
   servo6->writeServo(round(leftright));
}

void setup(){
  leftright = 90;
  servoset();
  	Serial.begin(9600);

  	mMotorDriver.begin(50);

  	ps2x = mMotorDriver.getSensor(E_PS2X);

  Serial.begin(9600);
  pinMode(5, OUTPUT);
}

void loop(){
  static int vibrate = 0;
  byte PSS_X = 0,PSS_Y = 0;
  ps2x->read_gamepad(false, vibrate);

  aim();
  if (ps2x->Button(2048)) {
    digitalWrite(5,HIGH);

  } else {
    digitalWrite(5,LOW);

  }

}
