RBE2002FinalProject/DualDCMotor.cpp
// set motor speed based on the given motor side and velocity
set motor speed based on the given motor side and velocity
set motor speed based on the given motor side and velocity
void DualDCMotor::setMotorSpeed(int rightSide, int velocity) {
  if (rightSide) {        
    if (velocity > 0) {   
      analogWrite(rightMotorFor, velocity);
      digitalWrite(rightMotorRev, LOW);
    }
    else if (!velocity) { 
      digitalWrite(rightMotorFor, LOW);
      digitalWrite(rightMotorRev, LOW);
    }
    else {
      digitalWrite(rightMotorFor, LOW);
      analogWrite(rightMotorRev, -velocity);
    }
  }
  else {                  
    if (velocity > 0) {   
      analogWrite(leftMotorFor, velocity);
      digitalWrite(leftMotorRev, LOW);
    }
    else if (!velocity) { 
      digitalWrite(leftMotorFor, LOW);
      digitalWrite(leftMotorRev, LOW);
    }
    else {
      digitalWrite(leftMotorFor, LOW);
      analogWrite(leftMotorRev, -velocity);
    }
  }
}
void DualDCMotor :: setMotorSpeed ( int rightSide , int velocity ) { if ( rightSide ) { if ( velocity > 0 ) { analogWrite ( rightMotorFor , velocity ) ; digitalWrite ( rightMotorRev , LOW ) ; } else if ( ! velocity ) { digitalWrite ( rightMotorFor , LOW ) ; digitalWrite ( rightMotorRev , LOW ) ; } else { digitalWrite ( rightMotorFor , LOW ) ; analogWrite ( rightMotorRev , - velocity ) ; } } else { if ( velocity > 0 ) { analogWrite ( leftMotorFor , velocity ) ; digitalWrite ( leftMotorRev , LOW ) ; } else if ( ! velocity ) { digitalWrite ( leftMotorFor , LOW ) ; digitalWrite ( leftMotorRev , LOW ) ; } else { digitalWrite ( leftMotorFor , LOW ) ; analogWrite ( leftMotorRev , - velocity ) ; } } }
set motor speed based on the given motor side and velocity
set motor speed based on the given motor side and velocity
// right motor is the target // set the robot to go forward // set the robot to stop // left motor is the target // set the robot to go forward // set the robot to stop