Seems to work can you find any mistakes?

I want to make this into a library for everyone to use.
Can you find any mistakes or portions of code that are confusing?
If so I will try to clarify.
Please test this if you have a stepper motor!

// This Arduino example demonstrates bidirectional operation of a 
// 28BYJ-48, which is readily available on eBay for $4.25 inc shipping,
// using a ULN2003 interface board to drive the stepper. The 28BYJ-48 
// motor is a 4-phase, 8-beat motor, geared down by a factor of 64. One 
// bipolar winding is on motor pins 1,3 and the other on motor pins 2,4. 
// Refer to the manufacturer's documentation of Changzhou Fulling 
// Motor Co., Ltd., among others.  The step angle is 5.625/64 and the 
// operating Frequency is 100pps. Current draw is 92mA.  
// Vin w USB power is 4.5v too slow for testing use 5v pin.

See attached PDE file

stepper2.pde (14.4 KB)

Make use of the IDE's auto-format feature: Tools -> Auto Format. It will make your code readable.

Line 67: const float STEPERDEG=float(64)*64/360; I think you meant STEPERDEG = 64.0 * 64.0 / 360.0;

Anytime you deal with floats it is a very good practice to always use decimals. Otherwise, the compiler may not cast the integers to floats like you expect. (If you're using integers on purpose, it is good to comment that.)

Line 152: " int step2=deg100*64*8/360/100; //rounded down"

What is the range of deg100? You are trusting the compiler to treat all of those constants as a long when they are just ints. Also if deg100 was say, "100" then you'd be multiplying 100*64*8 which is 51,200...

As for functionality, I'm really not sure what the code does, even with the supplied statements. Nor do I understand why huge chunks of code are commented out. Are those suppose to be ignored or considered? If ignored, why not just delete them before posting?

Any specific details about sourcing/pricing hardware will inevitably get out of date almost immediately. I suggest limiting the commentary to technical details.

Some random general thoughts:

Why can't you use the 4-wire stepper library ? From what all your phase sequences seem to be doing, which look like basic stepper sequencing to me, it's not obvious why the stepper library is in inappropriate.

I think you should consider reformatting the code a bit. Use conventional indentation and spacing between functions/methods.

#define dw digitalWrite
#define dm delayMicroseconds

undoubtedly saves some typing, but I am not 100% sure they help with readability. I've done this sort of thing plenty of times too.

I think all the code in cw() and ccw() and friends should be table driven. You could have a simple table of the phase combinations of mp1 ... mp4 and just step back and forth through the table. This would likely simplify your code a good deal.

Good luck

Thank you for your input!

line 67 - float() also casts which applies to the remainder of the line since the order of operations is left to right. In my opinion it is more readable. I appreciate your concern for that tiny integer.

line 152 - the maximum is 23,000.00 but without the decimal 2300000. Which is about 64 turns listed elsewhere in the code when that variable name is used. It is a long, but you may NOT use the entire range of a long integer. I am trusting the compiler to treat all those constants as long because the first operand is declared long. Again the order of operations is left to right. I have tested this piece of code.

The code in loop is commented out because I was using it for testing. You can use it too. The digitalWrite lines are commented out because they are redundant to execute, but there for readability. There are more that could be removed.

@gardner- As far as I know the stepper library does not work with half steps. Please correct me if I'm wrong. There are only 4 steps in a cycle. Mine has 8. If I removed the redundant code in cw() and ccw() it is easier not to be table driven. There would only be 1/4 as many lines.

I am using this library to detect motion at 50m with an IR laser in complete darkness 360 degrees. Detect motion with a cheap webcam during the day 360 degrees around. Detect motion at night without an expensive DSLR. Measure distance with 2 IR lasers 1m apart nearly parallel beams. At 3fps 12MP take a panorama in 4 seconds 360 degrees. At 4fps video mode take an infinite panorama 360 degrees x 1000 turns 8 seconds per turn. At 30fps HD video make a 3 Gigapixel image in a minute instead of an hour. For much less than $900: