Created
June 7, 2022 17:50
-
-
Save careyi3/1dccdc8e31437ed04d5c2625c00ea8d4 to your computer and use it in GitHub Desktop.
Simple demo code for a camera slider: https://www.thingiverse.com/thing:5405269
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AccelStepper.h> | |
const int speed = 700; | |
const double accl = 0.05; | |
AccelStepper stepper = AccelStepper(AccelStepper::DRIVER, DD3, DD2); | |
long prev_speed; | |
void setup() | |
{ | |
stepper.setMaxSpeed(speed); | |
prev_speed = 0; | |
} | |
void loop() | |
{ | |
int x = analogRead(A2); | |
x = map(x, 0, 1023, -1*speed, speed); | |
x = accl*x + (1-accl)*prev_speed; | |
if (x > speed/10 || x < -speed/10) { | |
stepper.setSpeed(x); | |
} else { | |
stepper.setSpeed(0); | |
} | |
stepper.runSpeed(); | |
prev_speed = x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment