Go Down

### Topic: fscale not in math.h? (Read 2270 times)previous topic - next topic

#### aefields

##### Nov 14, 2011, 08:25 pm
I tried using the fscale function from http://arduino.cc/playground/Main/Fscale
It results in an error:
'fscale' was not declared in this scope

As per the instructions, I have "#include <math.h>" at the start of my sketch.  The "get code" link goes to http://arduino.cc/playground/Main/Fscale?action=sourceblock&num=1  which has examples, but no link to a library.  Where is it?  How can I use fscale?

#### robtillaart

#1
##### Nov 14, 2011, 09:08 pm
you must copy the fscale() function directly into your sketch, it is not in a library

Code: [Select]
`float fscale( float originalMin, float originalMax, float newBegin, floatnewEnd, float inputValue, float curve){  float OriginalRange = 0;  float NewRange = 0;  float zeroRefCurVal = 0;  float normalizedCurVal = 0;  float rangedValue = 0;  boolean invFlag = 0;  // condition curve parameter  // limit range  if (curve > 10) curve = 10;  if (curve < -10) curve = -10;  curve = (curve * -.1) ; // - invert and scale - this seems more intuitive - postive numbers give more weight to high end on output  curve = pow(10, curve); // convert linear scale into lograthimic exponent for other pow function  /*   Serial.println(curve * 100, DEC);   // multply by 100 to preserve resolution     Serial.println();   */  // Check for out of range inputValues  if (inputValue < originalMin) {    inputValue = originalMin;  }  if (inputValue > originalMax) {    inputValue = originalMax;  }  // Zero Refference the values  OriginalRange = originalMax - originalMin;  if (newEnd > newBegin){    NewRange = newEnd - newBegin;  }  else  {    NewRange = newBegin - newEnd;    invFlag = 1;  }  zeroRefCurVal = inputValue - originalMin;  normalizedCurVal  =  zeroRefCurVal / OriginalRange;   // normalize to 0 - 1 float  /*  Serial.print(OriginalRange, DEC);     Serial.print("   ");     Serial.print(NewRange, DEC);     Serial.print("   ");     Serial.println(zeroRefCurVal, DEC);     Serial.println();     */  // Check for originalMin > originalMax  - the math for all other cases i.e. negative numbers seems to work out fine  if (originalMin > originalMax ) {    return 0;  }  if (invFlag == 0){    rangedValue =  (pow(normalizedCurVal, curve) * NewRange) + newBegin;  }  else     // invert the ranges  {      rangedValue =  newBegin - (pow(normalizedCurVal, curve) * NewRange);  }  return rangedValue;}`
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#### aefields

#2
##### Nov 17, 2011, 01:18 am
Thanks!

Go Up

Please enter a valid email to subscribe