int dirPin1=6;
int stpPin1=7;
int dirPin2=4;
int stpPin2=5;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(dirPin1, OUTPUT);
pinMode(stpPin1, OUTPUT);
pinMode(dirPin2, OUTPUT);
pinMode(stpPin2, OUTPUT);
}
void loop()
{
// put your main code here, to run repeatedly:
int horz=analogRead(A1);
int vert=analogRead(A0);
Serial.print("HORIZ: ");
Serial.print(horz);
Serial.print(", VERT: ");
Serial.println(vert);
if(horz>700)
{
stepper(dirPin1, stpPin1, false);
}
if(horz<300)
{
stepper(dirPin1, stpPin1, true);
}
if(vert>700)
{
stepper(dirPin2, stpPin2, false);
}
if(vert<300)
{
stepper(dirPin2, stpPin2, true);
}
delay(100);
}
void stepper(int stpPin, int dirPin, bool dirVal)
{
digitalWrite(dirPin, dirVal);
digitalWrite(stpPin, HIGH);
delayMicroseconds(50);
digitalWrite(stpPin, LOW);
delayMicroseconds(50);
}