This are my coding for the Stepper motor to turn if the condition is true, however I only need it to turn once, so if it's turning right, it wouldn't turn right again. The stepper motor would move again when the another condition is true, which it will turn right. What do i use? For loop ?
if (Val > 50)
{
// make the stepper do 1.5 rotations anti- CW
turns(2);
delay (1000);
return;
}
if(Val < 50)
{
// make the stepper do 1.5 rotations CW
turns(-2);
delay (1000);
return;
}
}
Once the motor has moved set a boolean flag to true to indicate that it has moved and don't move again whilst the flag is true. When you are ready to move set the flag to false.
UKHeliBob:
Once the motor has moved set a boolean flag to true to indicate that it has moved and don't move again whilst the flag is true. When you are ready to move set the flag to false.
Thanks for the reply. I want the machine to work independently, so if lets say if my value fall less then 50, the machine will turn Clockwise, however if the value fall below 50 again, I don't want the machine to turn clockwise again unless the value go above 50 , it turn Anti-clockwise and it won't move till the value hit below 50. Would the flag still work for my case? Sorry, im not good with coding.
if my value fall less then 50, the machine will turn Clockwise, however if the value fall below 50 again, I don't want the machine to turn clockwise again unless the value go above 50
Either I am not understanding what you want or you are not explaining it fully.
If the value falls below 50 then it cannot fall below 50 again without going above 50 in the meantime.
What I think you mean is that if the value stays below 50 the motor should not move again. In which case a flag variable will do what you want
flag = false
start of loop()
if value less than 50 and flag is false
move motor
flag = true
end if
if value greater than 50
flag = false
end if
end of loop()