I constructed an Arduino-controlled camera slider for my granddaughter. The purpose of the slider is time-lapse videos. I wrote a sketch that controls the ride. The code works correctly, but contains a “delay”. I tried to eliminate this “delay” and replace it with a millis() function. Unfortunately, nothing works for me. I would appreciate your help in solving this problem.
#include <AccelStepper.h>
#include <MultiStepper.h>
float Dp = 50 ; // Pass length (cm)
const int ng = 0 ; // Recording time (hours)
const int nm = 1 ; // Recording time (minutes)
const int ns = 0 ; // Recording time (seconds)
const int mo = 0 ; // Playback time (minutes)
const int so = 1 ; // Playback time (seconds)
const float Kog = 60 ; // Head rotation angle
const long Lz = (mo*60+so)*25; //Number of photos
const float Czp = ng*3600 + nm*60 + ns; //Travel time in sec
const float Omk = Czp*1000/Lz ; // Frame to frame spacing in millisec
const long Lkp = Dp*10*80; // Number of steps for the entire ride
const long Lkk = Lkp/(Lz-1); // Number of steps between frames
const long Lko = 3*(Kog/Lz)*8.8889; // Number of head rotation steps between frames at 32 microsteps
const long Pred =2500;
bool flag = true;
AccelStepper stepper1(1, 2, 5);
AccelStepper stepper2(1, 3, 6);
const int enablePin1 = 8;
const int enablePin2 = 8;
MultiStepper steppersControl;
long gotoposition[2];
void setup() {
Serial.begin(9600);
pinMode(enablePin1,OUTPUT);
pinMode(enablePin2,OUTPUT);
digitalWrite(enablePin1,LOW);
digitalWrite(enablePin2,LOW);
stepper1.setMaxSpeed(Pred); // Set maximum speed value for the stepper
stepper2.setMaxSpeed(Pred);
steppersControl.addStepper(stepper1);
steppersControl.addStepper(stepper2);
}
void loop() {
if(flag){
for(int i = 0; i <= (Lz-1); i++){
Serial.print("pozostało: ");
Serial.println(Lz-1-i);
gotoposition[0] = Lkk;
gotoposition[1] = Lko;
steppersControl.moveTo(gotoposition); // Calculates the required speed for all motors
steppersControl.runSpeedToPosition(); // Blocks until all steppers are in position
delay((Omk-Lkk*1000UL/Pred)); //I tried to replace it with millis()
stepper1.setCurrentPosition(0);
stepper2.setCurrentPosition(0);
}
}
flag=false;
digitalWrite(enablePin1,HIGH);
digitalWrite(enablePin2,HIGH);
}