Advertisement
Guest User

Untitled

a guest
Apr 7th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. // Include the Arduino Stepper Library
  2. #include <Stepper.h>
  3.  
  4. // Number of steps per output rotation
  5. const int stepsPerRevolution = 200;
  6. const int button1Pin = 12;
  7. const int button2Pin = 13;
  8.  
  9. // Create Instance of Stepper library
  10. Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
  11.  
  12. int Runtime = 0;
  13. int StpSpd = 60;
  14. int button1State = 0;
  15. int button2State = 0;
  16.  
  17. void setup()
  18. {
  19.   // set the speed at 60 rpm:
  20.   myStepper.setSpeed(StpSpd);
  21.   // initialize the serial port:
  22.   Serial.begin(9600);
  23.   pinMode(button1Pin, INPUT_PULLUP);
  24.   pinMode(button2Pin, INPUT_PULLUP);
  25. }
  26.  
  27. void loop()
  28. {
  29.   button1State = digitalRead(button1Pin);
  30.   button2State = digitalRead(button2Pin);
  31.   if (button1State == LOW) {
  32.     while (Runtime < 30)
  33.     {
  34.       Serial.println("clockwise");
  35.       myStepper.step(stepsPerRevolution);
  36.       StpSpd = StpSpd + 60;
  37.       if (StpSpd > 240) {
  38.        
  39.         StpSpd = 240;
  40.       }
  41.       myStepper.setSpeed(StpSpd);
  42.       Runtime++;
  43.     }
  44.     Runtime = 0;
  45.     StpSpd = 60;
  46.     myStepper.setSpeed(StpSpd);
  47.   }
  48.  
  49.   if (button2State == LOW) {
  50.     while (Runtime < 30)
  51.     {
  52.       Serial.println("counterclockwise");
  53.       myStepper.step(stepsPerRevolution);
  54.       StpSpd = StpSpd + 60;
  55.       if (StpSpd > 240) {
  56.        
  57.         StpSpd = 240;
  58.       }
  59.       myStepper.setSpeed(StpSpd);
  60.       Runtime++;
  61.     }
  62.     Runtime = 0;
  63.     StpSpd = 60;
  64.     myStepper.setSpeed(StpSpd);
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement