gabbyshimoni icon

speedup and down dc motor

gabbyshimoni | PRO | 02/06/19 01:46:01 PM UTC | 0 ⭐ | 1373 👁️ | Never ⏰ | []
C++ |

730 B

|

None

|

0 👍

/

0 👎

// Gabby Shimoni 02062019
// Move DC motor back and forth
 
#define motorInPin1 7
#define motorInPin2 8
#define enablePin 9
void setup() {
  pinMode(motorInPin1, OUTPUT);
  pinMode(motorInPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
}
 
void loop() {
  // speed up clockwise
  for (int Speed = 50; Speed <= 250; Speed += 50) {
    analogWrite(enablePin, Speed);
    digitalWrite(motorInPin1, HIGH);
    digitalWrite(motorInPin2, LOW);
    delay(2000);
  }
  // slow down clockwise
  for (int Speed = 250; Speed >= 50; Speed -= 50) {
    analogWrite(enablePin, Speed);
    digitalWrite(motorInPin1, HIGH);
    digitalWrite(motorInPin2, LOW);
    delay(2000);
  }
  // stop motor
  analogWrite(enablePin, 0);
  delay(1000);
}

Comments