How to control motor speed with potentiometer

Got it. Due to there being no esc component in the simulation, I had forgotten to think of adding a motor driver substitute in for it, partly thinking I hadn’t needed it too, thanks to other examples of people using no motor driver or transistor etc. I’ll be redoing the project with a motor driver and with the new code soon

It should be noted that this method produces a result that is uneven (three output codes occur five times, and one output code occurs only once), and can only give a 100% duty cycle output for one particular input value, which is 1023.
The divide by four method gives an even distribution (all output codes occur exactly four times), is simpler, quicker (avoids 32 bit arithmetic) and more intuitive.
The equivalent using map is

map (adcValue, 0, 1024, 0, 256);

(sp. "analogRead)

1 Like

How come on the arduino website and with other examples people use the map(adc value, 0, 1023, 0, 255) route rather than 1024 and 256? I’d have originally thought that the divide by 4 method would be slightly less accurate as 1023/4 is 255.75 which isn’t exactly 255 but I don’t know if that makes a big difference or not. But I take it that the AdcValue/4 method is better, I’ll make sure to use that to make things more concise and shorter

I am not responsible for the content of the Arduino website. You could ask them.

Laziness? Ignorance?

Alright, I see

1. 32-bit arithmetic is understood as the map() function uses "long data type".

2. Intuitiveness is understood from the range: 0, 1024, 0, 256 (1024/256 gives no fraction).

3. "All output codes occur exactly four times" -- not clearly understood.

adcValue is the input value.
The value returned by the map() function (or dividing the input value by four) is the output code or value.
A given input value will produce an output code or value.

No, intuitive, because if I ask you to portion a range up evenly, you'd use the division operator, not some obscure function called map.
If I ask you to serve up a pizza, you divide it, you don't map it.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.