.setSpeed() is it really, there's no difference between grabbing a value from a lookup and generating it there on the fly.
float speedLut = {20.0f, 21.001f, 22.023 ... etc };
long iteration = 0;
long lastSpeedUpdate = millis();
while (!endStopHit()) {
if (millis() > (lastSpeedUpdate + 200)) {
stepper.setSpeed(speedLut[iteration]);
iteration++;
lastSpeedUpdate = millis();
}
stepper.runSpeed();
}
You might be familiar with the kind of pattern above, and maybe that's not what you meant. Essentially here, you keep measuring the time using millis() (which returns the number of milliseconds since the arduino started), and each time another 200 have passed, you will increment your motor speed.
I'm sure you have a good reason for wanting to use a LUT, rather than writing a function, but you're right that it's fairly impractical for arduino - memory is very limited on these chips, and unless there's a truly monumental calculation to make, or you have so much other I/O to do in the same loop, I'd try hard to hammer your algorithm into a function that will calculate it on the fly. OR, you are counting on being able to achieve very high speeds (4000 steps per second+).
#include <AccelStepper.h>
long startTime;
AccelStepper stepper;
void setup() {
stepper.setMaxSpeed(1000);
}
float generateNewSpeed() {
long timeSince = millis() - startTime;
// clever algorithm here
float newSpeed = stepper.speed() * (timeSince / (timeSince - startTime));
return newSpeed;
}
void loop() {
startTime = millis();
stepper.setSpeed(40);
while (!endStopHit()) {
stepper.setSpeed(generateNewSpeed());
stepper.runSpeed();
}
}
boolean endStopHit() {
return false;
}Not tested, so not sure if it works, but compiles ok.