Mercurial > hg > beaglert
annotate core/Utilities.cpp @ 31:06fd2ffee605 matrix_gpio
Fixed command line bug same as per commit 30, just on a different branch
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 11 May 2015 11:45:03 +0100 |
parents | 8a575ba3ab52 |
children | 579c86316008 |
rev | line source |
---|---|
andrewm@0 | 1 /* |
andrewm@0 | 2 * Utilities.cpp |
andrewm@0 | 3 * |
andrewm@0 | 4 * Created on: Oct 27, 2014 |
andrewm@0 | 5 * Author: parallels |
andrewm@0 | 6 */ |
andrewm@0 | 7 |
andrewm@0 | 8 #include "../include/Utilities.h" |
andrewm@0 | 9 |
andrewm@0 | 10 // map() |
andrewm@0 | 11 // |
andrewm@0 | 12 // Scale an input value from one range to another. Works like its Wiring language equivalent. |
andrewm@0 | 13 // x is the value to scale; in_min and in_max are the input range; out_min and out_max |
andrewm@0 | 14 // are the output range. |
andrewm@0 | 15 |
andrewm@0 | 16 float map(float x, float in_min, float in_max, float out_min, float out_max) |
andrewm@0 | 17 { |
andrewm@0 | 18 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
andrewm@0 | 19 } |
andrewm@0 | 20 |
andrewm@0 | 21 // constrain() |
andrewm@0 | 22 // |
andrewm@0 | 23 // Clips an input value to be between two end points |
andrewm@0 | 24 // x is the value to constrain; min_val and max_val are the range |
andrewm@0 | 25 |
andrewm@0 | 26 float constrain(float x, float min_val, float max_val) |
andrewm@0 | 27 { |
andrewm@0 | 28 if(x < min_val) return min_val; |
andrewm@0 | 29 if(x > max_val) return max_val; |
andrewm@0 | 30 return x; |
andrewm@0 | 31 } |