/* Project: 1 DC motor, Arduino motor shield R3 Function: First DC motor spins at full speed forward then at half speed backward */ //********************************************************* const int dirA = 12; //direction of the DC motor attached to Channel A const int speedA = 3; //speed(PWM) of the DC motor attached to Channel A const int brakeA = 9; //brake of the DC motor attached to Channel A //********************************************************* void setup() { pinMode(dirA, OUTPUT); //initiates Motor Channel A pin pinMode(brakeA, OUTPUT); //initiates Brake Channel A pin } void loop(){ //forward at full speed digitalWrite(dirA, HIGH); //establishes forward direction of Channel A digitalWrite(brakeA, LOW); //disengage the brake for Channel A analogWrite(speedA, 255); //spins the motor on Channel A at full speed delay(3000); //sets delay for 3 seconds digitalWrite(brakeA, HIGH);//engage the brake for Channel A delay(1000); //sets delay for 1 second //backward at half speed digitalWrite(dirA, LOW); //establishes backward direction of Channel A digitalWrite(brakeA, LOW); //disengage the brake for Channel A analogWrite(speedA, 123); //spins the motor on Channel A at half speed delay(3000); //sets delay for 3 seconds digitalWrite(brakeA, HIGH); //engage the brake for Channel A delay(1000); //sets delay for 1 second }