Hello, I have modified a code that was operating two Motors and I was trying to simplify it to only run a single motor. There are no error codes when checking the program, but when uploaded to the Motor shield nothing happens.
Anyone suggestions on what is wrong with the code? I could use the dual motor code with just one motor, but trying to learn a little of the programming so I would like to understand why this code will not run (Sketch also attached).
const int MotorPin = 12;
const int MotorSpeedPin = 3;
const int MotorBrakePin = 9;
const int CW = HIGH;
const int CCW = LOW;
const int showComments = 1;// show comments in serial monitor
void setup() {
// motor A pin assignment
pinMode(MotorPin, OUTPUT);
pinMode(MotorSpeedPin, OUTPUT);
pinMode(MotorBrakePin, OUTPUT);
Serial.begin(9600);// serial monitor initialized
}
void loop() {
brake(0); // release brake
moveMotor(CCW, 100);// motor A rotate CCW at 100 PWM value
delay(3000);
brake(1);
brake(0);
moveMotor(CW, 255);
delay(5000);
brake(1);
}// loop end
/*
*
- moveMotor controls the motor
@param motor is char A or B refering to motor A or B.
@param dir is motor direction, CW or CCW
@speed is PWM value between 0 to 255
Example 1: to start moving motor A in CW direction with 135 PWM value
moveMotor('A', CW, 135);
*/
void moveMotor(int dir, int speed)
{
int motorPin;
int motorSpeedPin;
digitalWrite(motorPin, dir);// set direction for motor
analogWrite(motorSpeedPin, speed);// set speed of motor
}//moveMotor end
/*
- brake, stops the motor, or releases the brake
- @param motor is character A or B
- @param brk if 1 brake, if 0, release brake
- example of usage:
- brake('A', 1);// applies brake to motor A
- brake('A', 0);// releases brake from motor A
*/
void brake(int brk)
{
digitalWrite(MotorBrakePin, brk);// brake
delay(1000);
}
Motor_Test_05-02-20_Experimental2.ino (1.72 KB)