#include Servo lMotor, rMotor; // servo motor PWM pins const uint8_t rightMotorPin = 5; const uint8_t leftMotorPin = 6; const uint8_t spdBoost = 0; // ?? maybe used to adjust differences in motor speed ?? // alternate may be just to get the motor running const uint8_t turnTime = 0; void motorsInit() { lMotor.attach(leftMotorPin); rMotor.attach(rightMotorPin); } // right and left servos are going to spin in opposite directions // so the forward and reverse functions will apply alternate value ranges // test and use the forward or backwards (notional) settings void rightMotorForward(uint8_t spd) { spd = map(spd, 0, 255, 90, 0); rMotor.write(spd); } void rightMotorBackward(uint8_t spd) { spd = map(spd, 0, 255, 90, 180); rMotor.write(spd); } void rightMotorOff() { rMotor.write(90); // not used } void leftMotorForward(uint8_t spd) { spd = map(spd, 0, 255, 90, 180); lMotor.write(spd); } void leftMotorBackward(uint8_t spd) { spd = map(spd, 0, 255, 90, 0); lMotor.write(spd); } void leftMotorOff() { lMotor.write(90); // not used } void runMotors(int16_t leftSpd, int16_t rightSpd) { if(leftSpd >= 0) { leftMotorForward(constrain(leftSpd, 0, 255)); } else { leftMotorBackward(constrain(abs(leftSpd), 0, 255)); } if(rightSpd >= 0) { rightMotorForward(constrain(rightSpd, 0, 255)); } else { rightMotorBackward(constrain(abs(rightSpd), 0, 255)); } } // motorsOff() not used void motorsOff() { rMotor.write(90); lMotor.write(90); }