What does this example mean?

So I found this code online for testing my steppermotor with a RAMPS V1.4 (the code works, so that is not the problem)
Can someone tell me how this works?
Can I change the speed, steps,... of the stepper?

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2

#define SDPOWER            -1
#define SDSS               53
#define LED_PIN            13

#define PS_ON_PIN          12
#define KILL_PIN           -1

void setup() {
  pinMode(LED_PIN             , OUTPUT);
  pinMode(X_STEP_PIN          , OUTPUT);
  pinMode(X_DIR_PIN           , OUTPUT);
  pinMode(X_ENABLE_PIN        , OUTPUT);
  
  digitalWrite(X_ENABLE_PIN   , LOW);
 
}


void loop () {

  if (millis() %1000 <500) 
    digitalWrite(LED_PIN, HIGH);

  else
    digitalWrite(LED_PIN, LOW);

  if (millis() %10000 <5000) {
    digitalWrite(X_DIR_PIN    , HIGH);
  }
  else {
    digitalWrite(X_DIR_PIN    , LOW);
  }
  
    digitalWrite(X_STEP_PIN    , HIGH);
    delay(1);
    
    digitalWrite(X_STEP_PIN    , LOW);
 
}

The delay is what controls the speed. You can change to delayMicroseconds to get finer control to adjust it.

Robin2's simple stepper code tutorial may be of interest.

Does this also work with a RAMPV1.4?

Are you talking about the code in the tutorial? Did you read it?

Very probably, once you set the DIR and STEP pins appropriately. Enable may be needed too.

void loop()
{
  Every half-second, 
    switch the LED between ON and OFF

  Every five seconds, 
    switch the stepper direction pin between clockwise and counterclockwise.

  Step the stepper one step
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.