Take the 2-minute tour ×
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.

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|improve this question
add comment

1 Answer 1

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|improve this answer
    
Thanks! This is exactly what I needed. –  Max Isom Jun 17 '13 at 21:31
add comment

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.