Hello. Complete newbie to Arduino. I am working a project and trying to learn all I can. I was able to come up with this simple sketch from putting together pieces from sketches I found online, There will be a lot more when I'm done for sure. For now I'd like to add some some different speeds to this sketch. How do I go about doing that? I have pasted the sketch below. Thank you.
const int dirPin = 2; // Direction
const int stepPin = 3; // Step
// Motor steps per rotation
const int STEPS_PER_REV = 200;
void setup() {
// Setup the pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 400 pulses for making one full cycle rotation
for(int x = 0; x < 10000; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 10000; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}