Advertisement
skizziks_53

camera slider 10/26/18 v1.0

Oct 26th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. /*
  2.    Reddit slider project
  3.    October 26, 2018
  4.  
  5.    I made a couple of guesses here:
  6.    1. That you want a startup delay before the camera slider starts moving.
  7.    2. That you want to be able to set the step time, and the total number of steps that the slider motor moves.
  8.    3. You want the slider to run only one time, in one direction, for every time that the Arduino is turned on.
  9.       (If you added a button then you could have the thing reset itself by running in reverse at the same speed, but anyway)
  10. */
  11.  
  12. #define DIR 2
  13. #define STEP 3
  14. #define MS1 5 // <----------------------- It might have helped to explain what this is supposed to do.
  15. #define MS2 6 // <----------------------- It might have helped to explain what this is supposed to do.
  16. #define MS3 7 // <----------------------- It might have helped to explain what this is supposed to do.
  17.  
  18. int startUpDelay_milliseconds = 5000; // This is a time in milliseconds that the program will wait, before moving the motor.
  19. int slider_stepCounter = 0; // This will be used to count the slider steps.
  20. int slider_totalSteps = 1000; // This is the total amount of steps that you want the slider to take.
  21. int motorStepTime_milliseconds = 10; // This is the time amount for the motor half-step to take
  22. //                                      (the step time is this time x2, since the [on] and [off] states are both this long)
  23.  
  24. void setup() {
  25.   // put your setup code here, to run once:
  26.   pinMode (DIR, OUTPUT);
  27.   pinMode (STEP, OUTPUT);
  28.   pinMode (MS1, OUTPUT);
  29.   pinMode (MS2, OUTPUT);
  30.   pinMode (MS3, OUTPUT);
  31.   Serial.begin(9600);
  32.  
  33.   // ??? I am assuming that you wanted this stuff to run only one time?
  34.   // It would be helpful to explain what this part was supposed to do.
  35.   digitalWrite(MS1, LOW);
  36.   digitalWrite(MS2, LOW);
  37.   digitalWrite(MS3, LOW);
  38.   digitalWrite(DIR, HIGH); // This is the direction pin we assume...
  39.  
  40.   Serial.println("startUpDelay begin");
  41.   delay(startUpDelay_milliseconds); // This is the initial start-up delay taking place.
  42.   Serial.println("startUpDelay end");
  43. }
  44.  
  45.  
  46. void loop() {
  47.  
  48.   // put your main code here, to run repeatedly:
  49.  
  50.  
  51.   /*
  52.      I moved this into the setup() function above, since it made no sense here? You can delete it from here....
  53.     if (50 > 1) {
  54.       digitalWrite(MS1, LOW);
  55.       digitalWrite(MS2, LOW);
  56.       digitalWrite(MS3, LOW);
  57.       digitalWrite(DIR, HIGH);
  58.     }
  59.   */
  60.  
  61.   /*
  62.      A for() loop is not the best choice, if you only want it to work for a certain number of times and then stop and run no more.
  63.      The reason is because a for() loop contains its own counter, that get reset every time that the for() loop gets entered.
  64.  
  65.     for (int i = 0; i <= 1000; i++) {
  66.       digitalWrite (STEP, HIGH);
  67.       delay (10);
  68.       digitalWrite (STEP, LOW);
  69.       delay (10);
  70.       Serial.println (i);
  71.     }
  72.   */
  73.  
  74.   // A while() loop is a loop that allows using external variables to control how many times it runs.
  75.   // Because the variables are external, they don't get re-set every time the while() loop gets re-entered.
  76.   while (slider_stepCounter < slider_totalSteps) {
  77.     digitalWrite (STEP, HIGH);
  78.     delay (10);
  79.     digitalWrite (STEP, LOW);
  80.     delay (10);
  81.     slider_stepCounter++; // This is what performs the increment to make sure that the slider only does the number of steps you wanted and then stops completely.
  82.  
  83.     // Serial.println (slider_stepCounter); // This is not a good idea here, since using a slow Serial speed may slow this entire loop down.
  84.     // It is okay for testing, but you should comment it out for the final version. Un-comment the line if you want to use it.
  85.   }
  86.  
  87.   if (slider_stepCounter == slider_totalSteps) {
  88.     Serial.println ("slider is finished"); // This message will get sent when the slider is done.
  89.     slider_stepCounter++; // Increment this one more time, so that this message only displays once.
  90.   }
  91.  
  92. } // end of main loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement