I'm trying to vary the speed to a NEMA 17 stepper motor with an Arduino Mega, but I'm not really sure where to start. Can you turn on and off the pin quickly to control the "clock" speed for the steps?
Without getting into too much detail, the stepper moves because it has been given a single pulse, which moves it one step. A single pulse only moves it one step, or microstep, and after that it stands still, frozen in that position. A series of pulses moves it as far as all those pulses add up to, and at a rate based on the interval between those pulses.
If you are writing a loop that actually drives the stepper, as opposed to using something from the stepper library that allows you to set the speed, you will control the rate of movement by setting the time delay between each step.