How to scale numeric ranges
electro
Posts: 2
Sorry if this is clearly discussed somewhere else but I am having a little trouble getting my mind around the process of converting one range of numbers to another scale. For example: I want to drive a servo (300-1500) with the output of a Ping! module and have 1-50 from the ping map to the 300-1500 scale needed for the servo. I saw the explanation of this sort of operation in the Smart Sensors documentation but am still having trouble putting it into practice. If anyone can spare a couple seconds to try and maybe give an alternate perspective on how this is done I would be very grateful.
Thanks again!
Thanks again!
Comments
If you have the PING value in the variable "p" and you want the servo value in the variable "s", you do:
s = (p * 24) + 300
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store