Quote:
|
Originally Posted by chakorules
Here is the project file ZIP incase you want to open in easyC.
|
What Matt Adams said is correct.
Here's what's going on. In your "right_velocity" function the variables are all implicitly declared as auto storage class.
long enc_Right_Old_Count = 0;
What this means is that the variables are allocated as the function is entered and deleted when it exits. This is the default in C to save space - temporary variables in one function can use the space of variables in another function. And in your case you initialize them to 0, so that subtraction of 100-enc_Right_Old_Count will always be 100 since enc_Right_Old_Count is initialized to zero each time the function is entered.
Fortunately the fix is easy - you need to make "enc_Right_Old_Count" not get reinitialized each time. You can do this by declaring the variable as a global in the main function. That way it will only be initialized once when the program starts and not every time the function is declared. To do this, go to the main function, and double click on the "Globals" block and add it there.
Be sure to remove it from the right_velocity funtion otherwise the local declaration will override the global for that function and you'll still get the same results.
There might be better ways of doing this without global variables if you were hand coding in C, but this will solve the problem easily in EasyC.
Hope this helps.