This is what I have so far.
// give the motor control pins names:
const int PMWA = 3;
const int PMWB = 11;
const int BRAKEA = 9;
const int BRAKEB = 8;
const int DIRA = 12;
const int DIRB = 13;
unsigned long currentTime;
unsigned long loopTime;
void setup() {
//Setup Channel A
pinMode(DIRA, OUTPUT); //Initiates Motor Channel A pin
pinMode(BRAKEA, OUTPUT); //Initiates Brake Channel A pin
//Setup Channel B
pinMode(DIRB, OUTPUT); //Initiates Motor Channel A pin
pinMode(BRAKEB, OUTPUT); //Initiates Brake Channel A pin
currentTime = millis();
loopTime = currentTime;
}
void loop(){
//Motor A forward @ full speed
digitalWrite(DIRA, HIGH); //Establishes forward DIRection of Channel A
digitalWrite(BRAKEA, LOW); //Disengage the Brake for Channel A
analogWrite(3, 1023); //Spins the motor on Channel A at full speed - THIS LINE IS INCORRECT - SHOULD BE LIKE NEXT LINE
analogWrite(3, 255); //Spins the motor on channel A at full speed
//Motor B backward @ half speed
digitalWrite(DIRB, LOW); //Establishes backward DIRection of Channel B
digitalWrite(BRAKEB, LOW); //Disengage the Brake for Channel B
analogWrite(11, 512); //Spins the motor on Channel B at half speed - THIS LINE IS INCORRECT - SHOULD BE LIKE NEXT LINE
analogWrite(11, 128);
delay(3000);
digitalWrite(BRAKEA, HIGH); //Engage the Brake for Channel A
digitalWrite(9, HIGH); //Engage the Brake for Channel B
// the BRAKEB line above is also incorrect, it should refer to pin 8 - should be:
digitalWrite(BRAKEB, HIGH);//Engage the Brac
delay(1000);
//Motor A forward @ full speed
digitalWrite(DIRA, LOW); //Establishes backward DIRection of Channel A
digitalWrite(BRAKEA, LOW); //Disengage the Brake for Channel A
analogWrite(3, 128); //Spins the motor on Channel A at half speed
//Motor B forward @ full speed
digitalWrite(DIRB, HIGH); //Establishes forward DIRection of Channel B
digitalWrite(BRAKEB, LOW); //Disengage the Brake for Channel B
analogWrite(11, 255); //Spins the motor on Channel B at full speed
delay(3000);
digitalWrite(BRAKEA, HIGH); //Engage the Brake for Channel A
//digitalWrite(9, HIGH); //Engage the Brake for Channel B
//the BRAKEB line above is also incorrect, it should refer to pin 8 - should be:
digitalWrite(BRAKEB, HIGH);
delay(1000);
}
As you can see I have unsigned long currentTime;
unsigned long loopTime;
and underneath the void setup the currentTime = millis();
and loopTime = currentTime;.
To replace the four delay(), do I replace each delay() function with currentTime = millis();
if(currentTime >= (loopTime + 1000)).
Thanks for the help.