Quick question, servo make 0-180 become 180-0 how? code (arduino)

Hey guys i-am working on a little project but i got a little problem,

The servo goes the opposite direction of that i want it to go.

So when i turn the servo to 180 in code i want it to go to 0 i rl,
Also if i turn it to 0 in code i want it to turn to 180 in rl.
With ofcourse all the steps inbetween.

It must be such a simple thing but i just can't wrap my head around it at this moment.

here's a little nibble of my code:

    if(v <= 50) /* this limits steering, if v is less than 50 just write 50 */
    {
      steering.write(50);
    }
    else if(v >= 130) /* and also for the other side, if v is more than 130 just write 130 */
    {
      steering.write(130);
    }
    else{
    steering.write(v); /* if that's both not the case just write v */
    v = 0;
    break;
    }

end of the code nibble. (in this example it would be 50 to 130 instead of 0 to 180).

Who knows the answer? please tell meh.

wait, maybe like,

v = map(v, 180, 0, 0, 180);

would that work?

shit that totally worked,
any comments still welcome tough.

Turn it upside down.
Like the whole servo rotate it 180

1 Like

not possible sadly in what i-am using it in.
otherwise the best hardware solution ;)

How it's a box.

i can't reach it and don't want to bother breaking the whole thing apart.
So a software solution is easiest and i learn from it.

Ah ok. Plus you could have used negative numbers. At least with most servo controllers you c an.

1 Like