There is nothing about the code that would limit the value of “motorspeed” to be from 0 to 255. The idea is that you need to convert that value into a pair of motor speeds. For example, you could set m1 to 100 + motorspeed and m2 to 100 - motorspeed, and then limit m1 and m2 to be in the range [0:255].
Did you see how the original code does it? That code prevents m1Speed and m2Speed from being less than zero, and you should be able to easily add a couple of lines to prevent them from being greater than 255 as well.
Paul …
as they say it will not work …
was what I was saying in the previous message, repairs …
I get the following values in the array of sensors: 17850.7550, xxx, 2550, -2550, xxx, xxx, -17,850.
and I want the maximum speed of the motors are when I have the 2550 and -2550, or want to convert to 255 in 2550, and 17,850 to 0! and the same applies in negative values, understand?
You can calculate any mathematical function you want with the Arduino, but I have absolutely no idea what you are asking for or why you think our suggestion is not good enough.
It sounds like you really do not understand some basic things about PID. I think you should either read more about it somewhere else, or go back to the first line following example (called “rudimentary line following”) given here. Did you get that one to work already?