help in servo and map function

Good morning
First of all ty for your hard work....

I would like to say that I am completely new in the Arduino world and that the know-how in the electrotechnical field is just as limited....
I'm a Drones enthusiast and looking on Youtube I found some tutorials on how to use Arduino to test the functionality of the coupling: esc - brushles motors using the pwm output of arduino and a potentiometer connected to the analog pin.

(basically the equivalent of the potentiometer experiment that controls a led).
Now because I'm as curious as a monkey and I want to learn and not use the copy paste im writing to you for have an help...

The scheme of operation is similar as said to the one led potentiometer and in particular:
Connect the Potentiometer to an analog pin es A0
The motor connects to the esc and the esc is connects to a pwm pin e.g. 9.

after which you map the analog signal to feed the esc to run the engine.
The difference with the led is that in the code that o have found they use the library
servo.write(....)

the sketch type is this:

servo myservos; //but what a fantasy
int val, p;

void setup ()
myservo.attach(9);

void loop
           p = analogRead(A0);                  
          val = map(p, 0, 1023, 1000, 2000);
          myservo.write(val);                
          delay(20);

What I don't like, and what I'd like someone to explain to me, is:

  1. the map function :
    on the digital output does not allow values only from 1 to 255 (as for the led?) having put a scale from 1000 to 2000 does not affect the operation? or the values 1000 and 2000 are to be considered as a scale of possible values from 1 to 255 ?? ie the 256 possible values are then divided into small multiples and increase the potentiomentro then causes a really low increase in the engine??? Roll:

  2. the function myservo.write() should have a syntax like Syntax
    servo.write(angle) where angle: the value to write to the servo, from 0 to 180

so giving it a value between 1,000 and 2,000 makes sense?
I assume that: for the esc (which is different from a servo) the value is not an angle but precisely the value pwm to increase the speed of rotation?
But where is this documented??????

The only answers that i can think is that this code are wrong and the function to use is not servo.write but servo.writemicsoseconds...

So for me the right code must be:

servo myservos; 
int val, p;

void setup ()
myservo.attach(9);

void loop
           p = analogRead(A0);                  
          val = map(p, 0, 1023, 1000, 2000);
          myservo.writeMicroseconds(val);                
          delay(20);

Ty for any who want help me and sorry for disturb

If you want to use values like 1000 - 2000 you should be using servo.writeMicroseconds().

The standard servo.write() is intended to take an angle between 0 and 180 but if you give it a value outside that range it converts the call to writeMicroseconds() for you. This is documented in the header file Servo.h but I agree it could be confusing.

As for your confusion over 255 I guess that is related to hardware PWM i.e. analogWrite(). But that is irrelevant here because the Servo library doesn't use hardware PWM, which is why it will work on any digital pin and not just the PWM pins. But note that it does disable the use of some PWM pins for analogWrite whether they have servos connected to them or not...again this is documented in Servo.h.

Hope that helps - Steve

Was typing almost exactly what slipstick just posted, but will add this:

I don't think anything for an esc is really documented here; it's a servo library after all, not an esc one, and while escs may behave like servos they aren't servos. There was a long involved discussion years ago about (just as an example) a servo.detach() leaving the signal high if it was high at the instant of detach()-ment. That seemingly caused a problem for an esc-as-servo user (who insisted it was a bug in the library), but had no practical implications for an actual servo user (for whom it's just lazy coding, at worst.) It's not impossible that there may be other "limitations" when using the servo library to run an esc as a servo.

Ty for really quick reply...
Now I got a better idea and i have learn that is important read .h file.
Really ty for the help

slipstick:
the Servo library .... will work on any digital pin

Including, by the way, the analog inputs Ax which are digital pins.