I have a two-relay system set up to a DC motor. So, if I close one relay, the motor moves on one way and if I close the second relay (and open the first) the motor goes on the other direction.
I compare two variables (target inclination and real inclination) if they are not the same I would like to open one of the two relays UNTIL the are the same value.
Both variables are calculated based on inclinometer input and some aritmethics.
I do know how to calculate the variables, how to close the relay based in the comparation of variables and which relay open.
But I don´t know how I can tell to open the relay because the motor has reached target inclination.
How I can recalculate and compare constantly target inclination and real inclination when the relay is closed and the motor moving? Is this posible on Arduino? Is this multithreading?
Thank you very much, any ideas are welcome!