celem icon

accellstepper 28BYJ-48

celem | PRO | 01/17/12 07:31:13 PM UTC | 0 ⭐ | 6286 👁️ | Never ⏰ | []
C |

990 B

|

None

|

0 👍

/

0 👎

// accellsteppertest.ino
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// Set for 28BYJ-48 stepper
 
#include <AccelStepper.h>
 
#define FULLSTEP 4
#define HALFSTEP 8
 
//declare variables for the motor pins
int motorPin1 = 8;  // Blue   - 28BYJ48 pin 1
int motorPin2 = 9;  // Pink   - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
 
// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
 
void setup()
{    
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}
 
void loop()
{
  //Change direction at the limits
  if (stepper2.distanceToGo() == 0) {
    stepper2.moveTo(-stepper2.currentPosition());
  }
  stepper2.run();
}

Comments