I have written this code to power a servo motor by using a button and arduino ide does not find any errors in it. However when i load it onto my arduino the servo motor acts like it is not running any program. I have already checked if i messed up the inputs and if the motor works with other programs. (the serial monitor code was to check if the program works in general)
I think i misread something because i thought it would stand for the speed at which it rotates so i just used a convenient number. Im not that familiar with these things.
Try using numbers in the range 0 to 180 to get a feel for how it works. Assuming, that is, that you have got a conventional servo and not a continuous rotation "servo" unless that is what you really want
You cannot control the angle of the latter type, only its speed and direction. Which type do you have/want ?
The write() method is fairly smart as it converts to the internal use of microseconds.
void Servo::write(int value)
{
if(value < MIN_PULSE_WIDTH)
{ // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
if(value < 0) value = 0;
if(value > 180) value = 180;
value = map(value, 0, 180, SERVO_MIN(), SERVO_MAX());
}
this->writeMicroseconds(value);
}
MINPULSEWIDTH, 544 unless changed, is threshold for seeing the argument passed as a value in time, not degrees.
So both 200 and 500 are constrained to 180 degrees, then mapped into a range of pulse widths.
I'm not sure that is such a good idea. I like constraining to 0 .. 180, and I do not see the advantage to the flexibility afforded by allowing, say, 1000 .. 2000 to be used and interpreted differently, mostly because anyone doing would know enough to use writeMicroseconds().
Chicken door openers use degrees, more sophisticated code like found in radio control stuff happily uses pulse width.
writeMicroseconds() similarly constrains the input value, which is always nice to see but should probably not be why something works.