Hi,
You might try changing the speed tests:
else if (desired_speed < 0)
to, say
else if (desired_speed < -10)
and so on.
I havent tested this so YMMV.
Cheers.
int16_t Joystick::getAxisValue(joystick_axis_t axis)
{
uint8_t axis_pin;
int16_t offset;
if (axis == X_AXIS)
{
axis_pin = x_axis_pin_;
offset = x_offset_;
}
else //if (axis == Y_AXIS)
{
axis_pin = y_axis_pin_;
offset = y_offset_;
}
//read current joystick axis position.
int16_t raw_value = analogRead(axis_pin);
//apply offset.
raw_value -= offset;
//shift the range from 0 - 1023 to -512 to 512.
int16_t axis_value = map(raw_value, 0, 1023, -MAX_VALUE, MAX_VALUE);
//constrain values to -512 to 512 range.
axis_value = constrain(axis_value, -MAX_VALUE, MAX_VALUE);
//apply deadzone.
if (axis_value > -deadzone_ / 2 && axis_value < deadzone_ / 2)
return 0;
return axis_value;
}void loop() { // 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(JOYSTICK_PIN);
//shift the value from [0,1023] range to [-512, 512] range joystick_in = map(joystick_in, 0, 1023, -512, 512);
//deadzone if (abs(joystick_in) < 10) joystick_in = 0; // Map the raw analog value to speed range from -MAX_SPEED to MAX_SPEED int desired_speed = map(joystick_in, -512, 512, -MAX_SPEED, MAX_SPEED); // Serial.println(desired_speed);
// Based on the input, set targets and max speed stepper.setMaxSpeed(abs(desired_speed)); 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; }
stepper.run(); } You're welcome!
--
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.
else {stepper.stop();} if (desired_speed == 0 && stepper.speed() == 0) { // Prevent running off the end of the position range stepper.setCurrentPosition(0); } else if (desired_speed < -20) { stepper.moveTo(-1000000000); } else if (desired_speed > 20) { stepper.moveTo(1000000000); } else {stepper.stop();}