I am making a homemade printer that draws shapes and I’m trying to make a circle but the stepper motors are not working good. They aren’t as fluid as they should. Here is the code:
void loop() {
for (int angle = 0; angle <360; angle ++) {
float angleRad = angle*2*PI/360;
x = int(xInicial + cos(angleRad) * radi);
y = int(yInicial + sin(angleRad) * radi);
if (x <0) {
digitalWrite(dirPinX, LOW);
}
if (x >0) {
digitalWrite(dirPinX, HIGH);
}
x = abs(x);
if (y<0) {
digitalWrite(dirPinY, LOW);
digitalWrite(dirPinY2, LOW);
}
if (y>0) {
digitalWrite(dirPinY, HIGH);
digitalWrite(dirPinY2, HIGH);
}
x = abs(x);
y = abs(y)*2;
Serial.println(x);
for (int i=0; i<x; i++) {
digitalWrite(stepPinX, LOW);
digitalWrite(stepPinX, HIGH);
delayMicroseconds(200);
}
for (int j=0; j<y; j++) {
digitalWrite(stepPinY, LOW);
digitalWrite(stepPinY, HIGH);
digitalWrite(stepPinY2, LOW);
digitalWrite(stepPinY2, HIGH);
delayMicroseconds(200);
}
}
while(true);
}
The I thought that if I could run the “X axis” FOR and the “Y axis” FOR at the same time I will solve the problem. Is there anyway to do it?
Thanks