Linux.com

Home Linux Community Community Blogs General Linux Source Code for Arduino + Stepper + Potentiometer Video

Source Code for Arduino + Stepper + Potentiometer Video

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 Feed
  • Taylor 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

Upcoming Linux Foundation Courses

  1. LFD320 Linux Kernel Internals and Debugging
    04 Aug » 08 Aug - Virtual
    Details
  2. LFD405 Embedded Linux Development with Yocto Project
    04 Aug » 07 Aug - Santa Clara, CA
    Details
  3. LFD312 Developing Applications For Linux
    18 Aug » 22 Aug - Virtual
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board