├── README.md ├── examples ├── AnalogReadToVoltage │ └── AnalogReadToVoltage.ino └── MapFloatExample │ └── MapFloatExample.ino ├── keywords.txt ├── library.properties └── src ├── MapFloat.cpp └── MapFloat.h /README.md: -------------------------------------------------------------------------------- 1 | # MapFloat Documentation 2 | 3 | http://www.radishlogic.com/arduino/arduino-mapfloat-library-documentation/ 4 | -------------------------------------------------------------------------------- /examples/AnalogReadToVoltage/AnalogReadToVoltage.ino: -------------------------------------------------------------------------------- 1 | #include "MapFloat.h" 2 | 3 | #define PIN_ANALOG A0 4 | 5 | void setup() { 6 | Serial.begin(115200); // Initialize Serial 7 | while(!Serial); // Wait for Serial Connection 8 | } 9 | 10 | void loop() { 11 | // Read the Analog Value of A0 pin. 12 | int analogValue = analogRead(A0); 13 | 14 | // Computation for the Voltage Value using mapFloat 15 | float voltageValue = mapFloat(analogValue, 0, 1023, 0, 5); 16 | 17 | Serial.println(voltageValue); 18 | 19 | delay(1000); 20 | } 21 | -------------------------------------------------------------------------------- /examples/MapFloatExample/MapFloatExample.ino: -------------------------------------------------------------------------------- 1 | #include "MapFloat.h" 2 | 3 | void setup() { 4 | Serial.begin(115200); // Initialize Serial 5 | while(!Serial); // Wait for Serial connection 6 | } 7 | 8 | void loop() { 9 | float input, output; 10 | 11 | input = 32.5; 12 | output = mapFloat(input, 0.0, 100.0, 0.0, 1000.0); 13 | Serial.println(input); 14 | Serial.println(output); 15 | Serial.println("++++"); 16 | 17 | input = 45.67; 18 | output = mapFloat(input, 0.0, 100.0, 0.0, -1000.0); 19 | Serial.println(input); 20 | Serial.println(output); 21 | Serial.println("++++"); 22 | 23 | input = 321.83; 24 | output = mapFloat(input, 0.0, 1000.0, 1000.0, 2000.0); 25 | Serial.println(input); 26 | Serial.println(output); 27 | Serial.println("++++"); 28 | 29 | input = 563.09; 30 | output = mapFloat(input, 0.0, 1000.0, -1000.0, -2000.0); 31 | Serial.println(input); 32 | Serial.println(output); 33 | Serial.println("++++"); 34 | 35 | input = 743.88; 36 | output = mapFloat(input, 32.76, 1023.32, 3212.32, -5212.978); 37 | Serial.println(input); 38 | Serial.println(output); 39 | Serial.println("++++"); 40 | 41 | 42 | while(true); 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax for mapFloat 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | mapFloat KEYWORD2 14 | 15 | ####################################### 16 | # Constants (LITERAL1) 17 | ####################################### 18 | 19 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=MapFloat 2 | version=1.0 3 | author=Radish Logic 4 | maintainer=Josiah Sicad 5 | sentence=Map function that has a float for input, output and other parameters 6 | paragraph=Based on Arduino Map Function 7 | category=Other 8 | url=http://www.arduino.cc/en/Reference/SoftwareSerial 9 | architectures=avr 10 | includes=MapFloat.h 11 | 12 | -------------------------------------------------------------------------------- /src/MapFloat.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MapFloat.h 3 | 4 | Based on the Arduino Map function but this time input, output and parameters are float. 5 | 6 | This code is maintained by the team at RadishLogic.com 7 | */ 8 | 9 | 10 | #include "MapFloat.h" 11 | 12 | float mapFloat(float value, float fromLow, float fromHigh, float toLow, float toHigh) { 13 | return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow; 14 | } -------------------------------------------------------------------------------- /src/MapFloat.h: -------------------------------------------------------------------------------- 1 | /* 2 | MapFloat.h 3 | 4 | Based on the Arduino Map function but this time input, output and parameters are float. 5 | 6 | This code is maintained by the team at RadishLogic.com 7 | */ 8 | 9 | 10 | #ifndef MapFloat_h 11 | #define MapFloat_h 12 | 13 | float mapFloat(float value, float fromLow, float fromHigh, float toLow, float toHigh); 14 | 15 | #endif --------------------------------------------------------------------------------