Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a program for the arduino that takes a number as input and displays colors based on that input. At any given time, I know the value of the variables min and max where min is the minimum value of the input range and max is the maximum value of the input range. The problem is, in order for my program to work I have to convert this range to a range of 0-80. Is there a mathematical equation I can use for this?

share|cite|improve this question
up vote 4 down vote accepted

Denote min and max by $m$ and $M$ and use

$$f(x) = 80\cdot \frac{x-m}{M-m}$$

Then, $f$ proportionally maps the interval $[m,M]$ to $[0,80]$ as you asked. (In other words, as $x$ moves from $m$ to $M$, if it covered $a\%$ of the interval $[m,M]$, the result, $f(x)$ will have covered $a\%$ of the resulting interval $[0,80]$.

share|cite|improve this answer
    
Thanks! This is exactly what I needed. – Max Isom Jun 17 '13 at 21:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.