//The following code will make the motor run in clockwise and counter-clockwise directions. 

//Motor Driver
const int pinPwm = 3; // PWM is connected to pin 3.
const int pinDir = 2; // Direction is connected to pin 2.
int motorInput = 0; //Motor input
int motorInputScale = 0;


void setup() {
  Serial.begin(9600);//initiate serial communication
  //Motor

  //Motor controller pins setup
  pinMode(pinPwm, OUTPUT);
  pinMode(pinDir, OUTPUT);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
}

void loop() {
    // Control the motor according to the speed value.
    // Positive speed value = CW,
    // Negative speed value = CCW.
      if (digitalRead(A0)) {
        
          motorInputScale = -1;
          Serial.print("\n");
          Serial.print("Pin A0 Active");
        
      }
      else if (digitalRead(A1)) { 
          motorInputScale = 1;
          Serial.print("\n");
          Serial.print("Pin A1 Active");
      }
      else {
          motorInputScale = 0;
          Serial.print("\n");
          Serial.print("No Pin Active");
      }
      motorInput = 250;
      motorInput = motorInput * motorInputScale;
    

    if (motorInput >= 0) {
      analogWrite(pinPwm, motorInput);
      digitalWrite(pinDir, HIGH);
    }
    else {
      analogWrite(pinPwm, -motorInput);
      digitalWrite(pinDir, LOW);
    }    
}
