Skip to content

Instantly share code, notes, and snippets.

@ptrstovka
Created November 15, 2019 20:02
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 ptrstovka/89af3ffc1f013eb2e7ef62732ebc1786 to your computer and use it in GitHub Desktop.
Save ptrstovka/89af3ffc1f013eb2e7ef62732ebc1786 to your computer and use it in GitHub Desktop.
// defines pins numbers
const int stepX = 2;
const int dirX = 5;
const int stepY = 3;
const int dirY = 6;
const int stepZ = 4;
const int dirZ = 7;
const int enPin = 8;
void setup() {
// Sets the two pins as Outputs
pinMode(stepX,OUTPUT);
pinMode(dirX,OUTPUT);
pinMode(stepY,OUTPUT);
pinMode(dirY,OUTPUT);
pinMode(stepZ,OUTPUT);
pinMode(dirZ,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
digitalWrite(dirX,HIGH);
digitalWrite(dirY,LOW);
digitalWrite(dirZ,HIGH);
}
void moveX() {
for(int x = 0; x < 800; x++) {
digitalWrite(stepX,HIGH);
delayMicroseconds(1000);
digitalWrite(stepX,LOW);
delayMicroseconds(1000);
}
delay(200); // One second delay
}
void moveY() {
for(int x = 0; x < 800; x++) {
digitalWrite(stepY,HIGH);
delayMicroseconds(1000);
digitalWrite(stepY,LOW);
delayMicroseconds(1000);
}
delay(200); // One second delay
}
void loop() {
digitalWrite(dirX,HIGH);
digitalWrite(dirY,LOW);
moveX();
moveX();
moveX();
moveX();
moveX();
moveX();
moveX();
moveY();
moveY();
moveY();
moveY();
digitalWrite(dirX,LOW);
digitalWrite(dirY,HIGH);
moveX();
moveX();
moveX();
moveX();
moveX();
moveX();
moveX();
moveY();
moveY();
moveY();
moveY();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment