Hi, I m a hardware guy but interested in programming. This situation I cannot get my head around it.
well, my problem is the stepper motor keeps rotating despite the conditions being met. This is correct, but basically, I want the motor to rotate once (certain Steps or time period) and wait for the condition to occur again then rotate again.
In the coding, it keeps rotating until the other condition is met then to rotates the other way. I just want it to rotate just for those 20 steps then wait for the for the conditions to occur then trigger accordingly
thanks
So what you want is for the motor to rotate 20 steps when the LDRValue becomes less than 150 and stop even though the LDRValue is still less than 150. It can only start and rotate if the LDRValue becomes greater than 150 and then less than 150?
groundFungus:
So what you want is for the motor to rotate 20 steps when the LDRValue becomes less than 150 and stop even though the LDRValue is still less than 150. It can only start and rotate if the LDRValue becomes greater than 150 and then less than 150?
Yes, I want it to rotate that 20 steps when <150, then stops. Even though the condition still stands. Yes, sir, it will start to rotate when the condition is less than or greater than 150, but it must maintain that 20 steps.
UKHeliBob:
Adding a couple of boolean variables will help. Let's name them moveForward and moveBack. Set them both to false to begin with.
When the input to move the stepper forward occurs set moveForward to true and when the input to move the stepper back occurs set moveBack to true.
When the associated boolean is true move the stepper in that direction and set the boolean to false to prevent it happening again until required.
Have a look at the StateChangeDetection example to see how to detect when an input becomes HIGH or LOW rather than when it is HIGH or LOW
Thanks man, I need to do more readings on boolean Variables. BTW, is there any simple examples (moveForward and moveBack) you can provide me with or any links to those information will be most helpful. Thank you
There's nothing to study about boolean. It works like every other variable but can only have the values true or false. That's it. Now you know all there is to know about a Boolean. What you need to thing about is the logic, not the code.
Delta_G:
There's nothing to study about boolean. It works like every other variable but can only have the values true or false. That's it. Now you know all there is to know about a Boolean. What you need to thing about is the logic, not the code.