// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper(1, 1,2); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
pinMode(3,OUTPUT); // Enable
pinMode(1,OUTPUT); // Step
pinMode(2,OUTPUT); // Dir
digitalWrite(4,LOW); // Set Enable low
// full length rod, no microstepping
stepper.setMaxSpeed(2300);
stepper.setAcceleration(3700);
stepper.moveTo(900);
}
void loop()
{
// If at the end of travel go to the other end
if (stepper.distanceToGo() == 0)
stepper.moveTo(-stepper.currentPosition());
stepper.run();
}
I could guess that the top step rate will be 50% of a 16MHz Arduino, but I haven't read the
code to AccelStepper recently so might be wrong. If you are using microstepping you could
reduce the amount of microstepping to compensate for a slow maximum step rate, or use
a different stepper library or write your own code that is faster than AccelStepper.