Quote:
|
Originally Posted by doyler
Code:
static unsigned char servo1=0;
static unsigned char counter=0;
Ok, so theses make two variables, 1 is the servos position(?) and the other is the counter right
(i will go through it step by step)
|
Let me know if it worked as expected above.
Yes, servo1 is the position you set for the servo to move to. You can actually set it to any value you like. For instance if you have an RC unit, you could use that to move the servo.
The variable "servo1" could be completely replaced in this code sample with the system variable "pwm03" if you wanted. It isn't strictly needed, but it does make it easy to switch to a different pwm without having to change all your code.
This routine (Process_Data_From_Master_uP) in the default code is called the slow loop. It executes about
59 times per second
(in the EDU, FRC is 38 times per sec.), because that's how fast the radio packets come in. We're using that characteristic of the loop to make "counter" a cheap timer. Each loop equals 1/
59 second, so "counter<
59" , for example, will equal one second.
[edit]
P.S.
You can also change "servo1++;" to something like "servo1 += 5;" to make the servo move faster still. But be careful that the logic of the check "if (servo1 < 255)" catches servo1 before it tries to become larger than 255. When that happens servo1 cannot hold a value larger than 255, so it will suddenly become a completely unexpected value.