I'm trying to have the rotational speed of a stepper follow that of a sine wave with a period of x seconds. So it starts at a speed of 0 at 0°, picks up and peaks at 90°, slows back down to 0 at 180°, back up to peak speed at 270°, and back to 0 at 360°, if that makes sense. I'm trying to have the period of the rotation adjustable as well.
Right now I'm having trouble even getting it to spin with what I have now. if I start at 0 speed it doesn't step and therefore doesn't continue with the sketch, or at least I think that's what's happening. Any advice on how to do this would be appreciated.
I'm using the equation (topSpeed) * sin((pi * time) / period) for the wave.
#include <Stepper.h>
const int stepsPerRevolution = 200.000;
const float pi = 3.14159265358979;
const int period = 5; // Seconds
const int topSpeed = 100; // RPM
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
Serial.begin(9600);
}
void loop() {
for (int tStart = millis(); (millis()-tStart) < period;) {
float speed = topSpeed * (sin((pi * (millis() / 1000.000)) / period));
if (speed = 0) {
myStepper.setSpeed(1);
myStepper.step(1);
} else {
myStepper.setSpeed(speed);
myStepper.step(1);
}
}
}

