Skip to content

Instantly share code, notes, and snippets.

@eroberer
Created April 12, 2018 16:01
Show Gist options
  • Save eroberer/4540d66efbc1cfa845a31c1c5f830caa to your computer and use it in GitHub Desktop.
Save eroberer/4540d66efbc1cfa845a31c1c5f830caa to your computer and use it in GitHub Desktop.
const int stepPinX = 3;
const int dirPinX = 4;
const int stepPinY = 5;
const int dirPinY = 6;
char data = 0;
void setup() {
pinMode(stepPinX, OUTPUT);
pinMode(dirPinX, OUTPUT);
pinMode(stepPinY, OUTPUT);
pinMode(dirPinY, OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available() > 0) {
data = Serial.read();
Serial.print(data);
Serial.print("\n");
if(data == '1')
motorX(HIGH);
if(data == '2')
motorX(LOW);
if (data == '3')
motorY(HIGH);
if (data == '4')
motorY(LOW);
}
}
void motorX(bool value) {
digitalWrite(dirPinX, value);
for(int x = 0; x < 400; x++) {
digitalWrite(stepPinX, HIGH);
delayMicroseconds(300);
digitalWrite(stepPinX, LOW);
delayMicroseconds(300);
}
}
void motorY(bool value) {
digitalWrite(dirPinY, value);
for(int x = 0; x < 400; x++) {
digitalWrite(stepPinY, HIGH);
delayMicroseconds(300);
digitalWrite(stepPinY, LOW);
delayMicroseconds(300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment