I’m trying to put a line tracker on an oscillating servo on the front of my squarebot. My program isn’t running the way I want it to, however.
angleset == angle 1;
tracker = GetAnalogInput (2);
PrintToScreen ("%d\n", (int)tracker);
angleset == angle2;
My code goes into an infinite loop at the PrintToScreen line and just outputs the value the line tracker sends. Why doesn’t the program move to the next line? Also, is there an easier way to make the servo oscillate besides repeating the block of code for multiple angles? My goal is to find where the black line is, and if it’s off to the left slow down the left motor and if it’s off the to right slow down the right motor.
Are you doing this in MpLab, EasyC, or something else.
Looking at it I can’t see anything obviously wrong.
However to shorten things up and remove a spot where you could run into an error you can get rid of “angleset == angle1;” and make “SetServo(3, angleset);” into “SetServo(3, angle1);” and so on for the rest of the code.
If you need the Tracker Values later, store them in another Array for later.
Remember, IF you create an Array in C/C++ of say 50 Items, the Subscripts to access the Array is from 0 (Zero) to One Less than the Array Size.
I don’t get why this isn’t working. I tried your 2nd code using the loop and it does the same thing. The servo goes all the way to the right and continuously outputs the line tracker reading with the 1 second delay between each. The servo only moves once.