Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Reddit slider project
- October 26, 2018
- I made a couple of guesses here:
- 1. That you want a startup delay before the camera slider starts moving.
- 2. That you want to be able to set the step time, and the total number of steps that the slider motor moves.
- 3. You want the slider to run only one time, in one direction, for every time that the Arduino is turned on.
- (If you added a button then you could have the thing reset itself by running in reverse at the same speed, but anyway)
- */
- #define DIR 2
- #define STEP 3
- #define MS1 5 // <----------------------- It might have helped to explain what this is supposed to do.
- #define MS2 6 // <----------------------- It might have helped to explain what this is supposed to do.
- #define MS3 7 // <----------------------- It might have helped to explain what this is supposed to do.
- int startUpDelay_milliseconds = 5000; // This is a time in milliseconds that the program will wait, before moving the motor.
- int slider_stepCounter = 0; // This will be used to count the slider steps.
- int slider_totalSteps = 1000; // This is the total amount of steps that you want the slider to take.
- int motorStepTime_milliseconds = 10; // This is the time amount for the motor half-step to take
- // (the step time is this time x2, since the [on] and [off] states are both this long)
- void setup() {
- // put your setup code here, to run once:
- pinMode (DIR, OUTPUT);
- pinMode (STEP, OUTPUT);
- pinMode (MS1, OUTPUT);
- pinMode (MS2, OUTPUT);
- pinMode (MS3, OUTPUT);
- Serial.begin(9600);
- // ??? I am assuming that you wanted this stuff to run only one time?
- // It would be helpful to explain what this part was supposed to do.
- digitalWrite(MS1, LOW);
- digitalWrite(MS2, LOW);
- digitalWrite(MS3, LOW);
- digitalWrite(DIR, HIGH); // This is the direction pin we assume...
- Serial.println("startUpDelay begin");
- delay(startUpDelay_milliseconds); // This is the initial start-up delay taking place.
- Serial.println("startUpDelay end");
- }
- void loop() {
- // put your main code here, to run repeatedly:
- /*
- I moved this into the setup() function above, since it made no sense here? You can delete it from here....
- if (50 > 1) {
- digitalWrite(MS1, LOW);
- digitalWrite(MS2, LOW);
- digitalWrite(MS3, LOW);
- digitalWrite(DIR, HIGH);
- }
- */
- /*
- 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.
- The reason is because a for() loop contains its own counter, that get reset every time that the for() loop gets entered.
- for (int i = 0; i <= 1000; i++) {
- digitalWrite (STEP, HIGH);
- delay (10);
- digitalWrite (STEP, LOW);
- delay (10);
- Serial.println (i);
- }
- */
- // A while() loop is a loop that allows using external variables to control how many times it runs.
- // Because the variables are external, they don't get re-set every time the while() loop gets re-entered.
- while (slider_stepCounter < slider_totalSteps) {
- digitalWrite (STEP, HIGH);
- delay (10);
- digitalWrite (STEP, LOW);
- delay (10);
- 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.
- // Serial.println (slider_stepCounter); // This is not a good idea here, since using a slow Serial speed may slow this entire loop down.
- // 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.
- }
- if (slider_stepCounter == slider_totalSteps) {
- Serial.println ("slider is finished"); // This message will get sent when the slider is done.
- slider_stepCounter++; // Increment this one more time, so that this message only displays once.
- }
- } // end of main loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement