Advertisement
gabbyshimoni

speedup and down dc motor

Feb 6th, 2019
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. // Gabby Shimoni 02062019
  2. // Move DC motor back and forth
  3.  
  4. #define motorInPin1 7
  5. #define motorInPin2 8
  6. #define enablePin 9
  7. void setup() {
  8.   pinMode(motorInPin1, OUTPUT);
  9.   pinMode(motorInPin2, OUTPUT);
  10.   pinMode(enablePin, OUTPUT);
  11. }
  12.  
  13. void loop() {
  14.   // speed up clockwise
  15.   for (int Speed = 50; Speed <= 250; Speed += 50) {
  16.     analogWrite(enablePin, Speed);
  17.     digitalWrite(motorInPin1, HIGH);
  18.     digitalWrite(motorInPin2, LOW);
  19.     delay(2000);
  20.   }
  21.   // slow down clockwise
  22.   for (int Speed = 250; Speed >= 50; Speed -= 50) {
  23.     analogWrite(enablePin, Speed);
  24.     digitalWrite(motorInPin1, HIGH);
  25.     digitalWrite(motorInPin2, LOW);
  26.     delay(2000);
  27.   }
  28.   // stop motor
  29.   analogWrite(enablePin, 0);
  30.   delay(1000);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement