Hello to all..
I'm stuck on a portion of code in the loop of a sketch to control a motor using a H-Bridge (L293NE)
Having an error around a fixed value, I want to move the motor in FWD/REV, if the error is above 2 units or below -2 units. In the mean time, if the error is equal os less than +2 or -2, I want the motor stop.
Here´s the code:
With the previous code, the motor moves when error reaches -2 units and stops correctly if error not exceeds that -2 value,... but it doesn´t rotates opposite when reaching +2 units.
Am I doing something wrong?...
It would be my poor knowledge implementing code... or a better code to do what I want..
Thanks in advance...
Thanks Power_Broker & LarryD...
This thing is driving me nuts.. (sorry)..
I have change code in different ways using if else a bunch of fashions..
Please.. see this code:
This way it does oppsite from my first post:
It rotates when going >2 units and stops when below 2 (positive)... but it doesn´t starts when going negative ...
Keep on trying gents.. I´ll post any lucky result.
Thanks a million Power_Broker...
It works!!!!...
I´m too old fo this games.. (64 and counting).
Things were a lot easier when vacuum tubes and analog resolvers...
I owe you a big ONE.
I´ll try to understand what I was doing... and keep learning.
I´m too old for this games.. (64 and counting)..
Those days when vacuum tubes and mechanical resolvers... ..
Thanks again and... to complete the whole thing the goal is to turn the motor at intervals.. In other words:
The idea is to use the mechanical motor output to re-align the error. So ¿ Is OK to insert a delay of milliseconds on each case waiting for realignment?.
pacheco:
I´m too old for this game ...
I´ll try to understand what I was doing... and keep learning.
Hi pacheco. If you find too many chains of "if else if" confusing, then there is another way to structure it. If you make all the conditions mutually exclusive (only one is true) then you can keep it very simple. Sure it's a little less run time efficient, but not enough to make any meaningful difference in most situations.
For example
if (error < -2) ...
if (error > 2) ...
if (error >=-2 && error <=2) ...