Skip to content

Instantly share code, notes, and snippets.

@Cosmologist
Last active November 16, 2015 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cosmologist/67e8cfdea8b63e6b36b4 to your computer and use it in GitHub Desktop.
Save Cosmologist/67e8cfdea8b63e6b36b4 to your computer and use it in GitHub Desktop.
int Distance = 0; // Record the number of steps we've taken
// the setup function runs once when you press reset or power the board
void setup() {
// Enable control signal pin
pinMode(11, OUTPUT);
// Dir pin
pinMode(12, OUTPUT);
// Step pin
pinMode(13, OUTPUT);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
// the loop function runs over and over again forever
void loop() {
// Step signal On
digitalWrite(13, HIGH);
// Delay
delay(1);
// Step signal off
digitalWrite(13, LOW);
// Delay
delay(1);
// Increase distance
Distance = Distance + 1;
// Check to see if we are at the end of our move
if (Distance == 3200) {
// We are! Reverse direction (invert DIR signal)
if (digitalRead(12) == LOW) {
digitalWrite(12, HIGH);
}
else {
digitalWrite(12, LOW);
}
// Reset our distance back to zero since we're // starting a new move
Distance = 0;
// Now pause for half a second
delay(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment