--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi,
new version 1.45 implements this. Thanks for the
suggestion.
Cheers.
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
//Set up Stepper Shield and Accel Library
//adapted from Adafruit_MotorShield / Accel_MultiStepper sample
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers
Adafruit_StepperMotor *myStepper = AFMStop.getStepper(200, 2);
void forwardstep2() {
myStepper->onestep(FORWARD, DOUBLE);
}
void backwardstep2() {
myStepper->onestep(BACKWARD, DOUBLE);
}
AccelStepper stepper(forwardstep2, backwardstep2);
void setup()
{
AFMStop.begin(); // Start the top shield
Serial.begin(9600);
Serial.println("Accel / Decel test");
}
int runState = HIGH;
int faderSpeed = 0;
int faderAccel = 20;
int faderMaxspeed = 100;
#define INPUT_READ_INTERVAL 100
unsigned long last_input_time = 0;
int last_speed = 0;
void loop()
{
// Code adapted from https://groups.google.com/forum/#!topic/accelstepper/CVO28NaApKY
// Every INPUT_READ_INTERVAL milliseconds, read inputs.
// We do this infrequently to prevent interfering
// with the stepper motor high speed stepping
// Get the current joystick position as analog value
unsigned long current_time = millis();
if (current_time - last_input_time > INPUT_READ_INTERVAL)
{
int joystick_in = analogRead(0);
// Map the raw analog value to speed range from -MAX_SPEED to MAX_SPEED
int desired_speed = map(joystick_in, 0, 1023, -faderMaxspeed, faderMaxspeed);
if(desired_speed != last_speed) {
Serial.println(desired_speed);
last_speed = desired_speed;
}
// Based on the input, set targets and max speed
stepper.setMaxSpeed(abs(desired_speed*3));
stepper.setAcceleration(faderAccel);
stepper.setDeceleration(faderAccel); //Only works with modified library from https://groups.google.com/forum/#!topic/accelstepper/kAT9ZG2IRhM
if (desired_speed == 0 && stepper.speed() == 0)
{
// Prevent running off the end of the position range
stepper.setCurrentPosition(0);
}
else if (desired_speed < 0)
{
stepper.moveTo(-1000000000);
}
else if (desired_speed > 0)
{
stepper.moveTo(1000000000);
}
last_input_time = current_time;
}
if (runState) stepper.run();
else myStepper->release();
}new version 1.45 implements this. Thanks for the
suggestion.
However Equation 15 should be implemented into the lib, since the enumerator change from 2 to 1 in _c0 calculation is empiric.