Stepper motor with SEA5045

I'm using SEA5045 micro stepper driver, and arduino mega , nema 17 motor ,
Can you please anyone explain the code link by line, how its moving. the code perfect stepper is moving.

`#define Pulse 9

#define Dir 8

long delay_Micros =1800; // Set value

long currentMicros = 0; long previousMicros = 0;

void setup()






void loop()


currentMicros = micros();

if(currentMicros - previousMicros >= delay_Micros)


previousMicros = currentMicros;


delayMicroseconds(5000 ); //Set Value


} }`

@SHASHI448 your topic has been moved to a more suitable location on the forum.

Can you please read How to get the best out of this forum. Next apply the code tags as explained.

Rather than going through each line, why don't you tell is which specific bits you don't understand, then it doesn't look like we're documenting your class assignment for you.

millis and micros return unsigned long, not long

The logic behind delay_Micros, current micros,previousmicros

It's the same as the logic behind the well-documented blink-without-delay example in the IDE, just 1000 times faster.

1 Like

millis() and micros() return the total elapsed units since the cpu was restarted.

currentXXX keeps a convenient copy of XXX for comparison, so the value doesn’t change during the comparison

previousXXX keeps a record of that =value when you ‘set’ it.

if(currentMicros - previousMicros >= delay_Micros)

You might imagine this as if (the elapsed time >= theDuration) then..l
Performs a test to see if the delay_XXX period has elapsed.

delay() STOPS everything for the designated duration. Nothing else happens, button tests, relays, flashing LEDs, nothing.

I wrote this yesterday.

See if it helps.

1 Like