Home > Back-end >  Making a number bigger when its small, and smaller when big
Making a number bigger when its small, and smaller when big

Time:05-15

i have been coding in python for some time now, and am trying to make a robotic hand in combination with Arduino. I have 2 servo's facing the opposite way (small electric motors) which means that when i rotate them by the same angle, the second one will rotate the opposite way. As the servo can't handle negative integers, i have to come with a solution that basically "reverses" the integer. What i mean by that is that if the number is greater than the middle point (45 in this case) i want it to be smaller, so lets say we have 46 it should be 44 and 47 -> 43 so on. How would i go about creating this? Thanks for reading.

CodePudding user response:

This is just a tricky algorithm:

edge = 45
number = 44
result = edge   (edge - number)

result will be 46

edge = 45
number = 47
result = edge   (edge - number)

result will be 43

  •  Tags:  
  • math
  • Related