I tried this code and it worked:
void loop()
{
int y = 104;
int x2 = vertical2.currentPosition();
int z2 = y-x2;
int x1 = horizontal2.currentPosition();
int z1 = y-x1;
horizontal2.moveTo(z1);
horizontal2.run();
vertical2.moveTo(z2);
vertical2.run();
}
However, the problem is that when the above code was placed inside a loop such as if loop
, it was not working. Can anyone help me solve this problem? I am using accelStepper library for the code above.
void loop()
{
int dummy=1;
if(dummy==1)
{
int y = 104;
int x2 = vertical2.currentPosition();
int z2 = y-x2;
int x1 = horizontal2.currentPosition();
int z1 = y-x1;
horizontal2.moveTo(z1);
horizontal2.run();
vertical2.moveTo(z2);
vertical2.run();
}
}
loop
function? Does it make sense to sety=104
over and over again? Also:if
is not a loop. $\endgroup$if
is not a loop! Also, is this really your exact code? Or did you rewrite it here, perhaps avoiding a typo you have in your real code? $\endgroup$