Source Code for Arduino + Stepper + Potentiometer Video

149

 

#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