I've had several requests for the code I used in my video Arduino + Stepper + Potentiometer.
As the description says, I used the Motorknob example that comes with the Arduino IDE.
Here is my modified code with comments.
#include //How many steps does your motor have #define STEPS 48
//Start new Stepper class with 48 steps (STEPS defined above) //Motor is connected to pins 4, 5, 6 & 7 Stepper stepper(STEPS, 4, 5, 6, 7);
//Create starting position for motor / pot int previous = 0;
void setup() {
//How fast will we try to move the motor
//If your motor stutters, its too fast so just lower the value stepper.setSpeed(180); }
void loop() {
//Read analog 0 (pot) and map it to the range of the motor int val = map(analogRead(0), 0, 1023, 48, 0);
//Move motor based off of last recorded position stepper.step(val - previous);
//Store current position previous = val; }
Enjoy,
Shawn



Comments
Subscribe to Comments FeedTaylor Said:
#include //How many steps does your motor have #define STEPS 48 //Start new Stepper class with 48 steps (STEPS defined above) //Motor is connected to pins 4, 5, 6 & 7 Stepper stepper(STEPS, 4, 5, 6, 7); After (# include) you need to put for it to work
nikitz Said:
Your first line should be : #include