DC Motor Experiments

1 Write the code to make the DC motor turn in the opposite direction for two seconds and then stop.
int Input1 = 6;   // must be one of the PWM ~ pins
int Input2 = 5;   // must be one of the PWM ~ pins

void setup() {
  pinMode(Input1, OUTPUT);
  pinMode(Input2, OUTPUT);  

  // turn on motor to spin in the other direction
  digitalWrite(Input1, LOW);
  digitalWrite(Input2, HIGH);
  delay(2000);
  
  // stop the motor
  digitalWrite(Input1, LOW);	
  digitalWrite(Input2, LOW);
}

void loop() {
}
2 Write the code to make the DC motor turn in one direction for two seconds, and then in the opposite direction for another two seconds, and then stop.
int Input1 = 6;   // must be one of the PWM ~ pins
int Input2 = 5;   // must be one of the PWM ~ pins

void setup() {
  pinMode(Input1, OUTPUT);
  pinMode(Input2, OUTPUT);  

  // turn on motor to spin in one direction for two seconds
  digitalWrite(Input1, HIGH);
  digitalWrite(Input2, LOW);
  delay(2000);
	
  // turn on motor to spin in the other direction
  digitalWrite(Input1, LOW);
  digitalWrite(Input2, HIGH);
  delay(2000);

  // stop
  digitalWrite(Input1, LOW);
  digitalWrite(Input2, LOW);
}

void loop() {
}
3 Write the code to make the DC motor turn slower.

What is the smallest value you can have where the motor still turns? Keep in mind that when the batteries get weaker the motor might not turn using this value.
int Input1 = 6;   // must be one of the PWM ~ pins
int Input2 = 5;   // must be one of the PWM ~ pins

void setup() {
  pinMode(Input1, OUTPUT);
  pinMode(Input2, OUTPUT);  

  // turn on motor to spin slower
  // use analogWrite instead of digitalWrite, and use a number less than 256
  analogWrite(Input1, 100);
  analogWrite(Input2, 0);
}

void loop() {
}
4 Write the code to make the DC motor ramp up, i.e. start slow and then turn faster and faster.
int Input1 = 6;   // must be one of the PWM ~ pins
int Input2 = 5;   // must be one of the PWM ~ pins

void setup() {
  pinMode(Input1, OUTPUT);
  pinMode(Input2, OUTPUT);  

  for (int speed=80; speed<256; speed++) {
    analogWrite(Input1, speed);
    analogWrite(Input2, 0);
    delay(100);    
  }
}

void loop() {
}