// slowly accelerate to desired motor speed - no library
const int dirPin = 2,
stepPin = 3;
long usDelay, // pause between half-step
ramp = 50; // rate of acceleration
unsigned long timer,
timeout = 1000,
multiplier = 16; // start value multiplier, maximum = 16
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, HIGH);
for (usDelay = timeout * multiplier; usDelay > timeout; usDelay -= ramp) { // decrease step delay
onestep(); // step the motor
}
}
void loop() {
if (micros() - timer >= timeout) { // use timeout value for constant rotation speed
timer = micros(); // reset timer to wait for next pulse
onestep();
}
}
void onestep() {
digitalWrite(stepPin, LOW);
delayMicroseconds(usDelay);
digitalWrite(stepPin, HIGH);
delayMicroseconds(usDelay);
}