We’ll need just a little more information.
Are you sure your range isn’t 0-255? That’s more typical. Just checking…
Also, when you say fast and slow, i assume you mean forward speed. I didn’t see any discussion about going in reverse.
Let me take a crack at restating what you want the program to do:
- If Turn is between 0 and 127, you want the platform/robot/vehicle to drive to the right, and values between 129 and 250 to drive to the left.
- You also want Turn to encode the forward speed: 0=FASTEST, gradually changing to 127=SLOWEST, and again 129=SLOWEST, gradually increasing to 250=FASTEST.
- If Turn is 128, stop.
If you are driving the motors with PWM signals, they’ll want values from 0=off to 255=max on. You’ll need to make sure you know what values to pass them and fix the code below, if necessary.
Here’s some pseudo code for you. Does this look right?
Turn = constrain(Turn, 0, 250) // ensure range is valid
If Turn<=127 then
Direction = RIGHT
Speed = map(Turn, 0, 127, 255, 0) // PWM 0=off, 255=max on
Else if Turn >=129 then
Direction = LEFT
Speed = map(Turn, 129, 250, 0, 255) // PWM 0=off, 255=max on
Looks like a fun project. Good luck!