I have been able to create this simple code attached with help from the forum to "Jiggle" a stepper motor 28BYJ-48 motor back and forth 6 times.
I want to repeat this "Jiggle" code at a time I can adjust in the code, for example every 10 minutes.
How can this be coded without repeating the sequence over and over in the code with a Delay between each Jiggle?
Thank You
// Turn on current to motors
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
// 2 sec delay for motors
delay(2000);
// Here is the jiggle, 6 times and back to where it was
for (int s=0; s<1024; s++) {
stepper.stepCCW();
}
for (int s=0; s<1024; s++) {
stepper.stepCW();
}
for (int s=0; s<1024; s++) {
stepper.stepCCW();
}
for (int s=0; s<1024; s++) {
stepper.stepCW();
}
for (int s=0; s<1024; s++) {
stepper.stepCCW();
}
for (int s=0; s<1024; s++) {
stepper.stepCW();
}
// Turn off hold current
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
Start by putting your "6 times jiggle" code in a for loop to avoid writing the same code over and over again
// Here is the jiggle, 6 times and back to where it was
for (int x = 0; x < 3; x++)
{
for (int s = 0; s < 1024; s++)
{
stepper.stepCCW();
}
for (int s = 0; s < 1024; s++)
{
stepper.stepCW();
}
}
Then let loop() repeat the code with a 10 minute delay()
If the sketch needs to do anything during the 10 minute delay then you cannot use the delay() function. Does the sketch need to do anything during that 10 minutes ?
Thank you so much. I will attempt to integrate the "for" statement you so kindly provided.
There is nothing to do during the delay. Just wait 10 minutes and Jiggle again. This Jiggle sequence will occur 5 times then the program will move onto rotating the motor 180 degrees then start the Jiggle again. So I should be fine using the Delay command.
I just copied and pasted to replace my child like Jiggle code and it works great. Much more sophisticated. Im going to look into how that FOR statement and how it works. Thank you again!
Well after using it, to support trouble shooting, it would be helpful to have a counter print a value so I can tell where we are in the delay. Is that possible if delay, pauses the processing?