Difference between revisions of "Component: Map Function (Calculation)"
From Flowcode Help
Jump to navigationJump to search(5 intermediate revisions by 2 users not shown) | |||
Line 37: | Line 37: | ||
==Examples== | ==Examples== | ||
+ | A simple example showing how to take a value from an adc input with the range 0-255 and mapping this to a predetermined range of 50-150 to drive a PWM output. | ||
− | + | {{Fcfile|MappingADCtoPWM.fcfx|Mapping ADC to PWM}} | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Macro reference== | ==Macro reference== | ||
− | === | + | ===MapByte=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MapByte''' |
|- | |- | ||
− | | colspan="2" | Map function for | + | | colspan="2" | Map function for byte type variables |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" | Value | | width="90%" | Value | ||
|- | |- | ||
| colspan="2" | Main variable used for map function | | colspan="2" | Main variable used for map function | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" | InMin | | width="90%" | InMin | ||
|- | |- | ||
| colspan="2" | Lowest input value | | colspan="2" | Lowest input value | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" | InMax | | width="90%" | InMax | ||
|- | |- | ||
| colspan="2" | Highest value input | | colspan="2" | Highest value input | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" | OutMin | | width="90%" | OutMin | ||
|- | |- | ||
| colspan="2" | Lowest value after conversion | | colspan="2" | Lowest value after conversion | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" | OutMax | | width="90%" | OutMax | ||
|- | |- | ||
Line 94: | Line 82: | ||
| colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | | colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | === | + | ===MapFloat=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MapFloat''' |
|- | |- | ||
− | | colspan="2" | Map function for | + | | colspan="2" | Map function for floating point type variables |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" | Value | | width="90%" | Value | ||
|- | |- | ||
| colspan="2" | Main variable used for map function | | colspan="2" | Main variable used for map function | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" | InMin | | width="90%" | InMin | ||
|- | |- | ||
| colspan="2" | Lowest input value | | colspan="2" | Lowest input value | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" | InMax | | width="90%" | InMax | ||
|- | |- | ||
| colspan="2" | Highest value input | | colspan="2" | Highest value input | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" | OutMin | | width="90%" | OutMin | ||
|- | |- | ||
| colspan="2" | Lowest value after conversion | | colspan="2" | Lowest value after conversion | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" | OutMax | | width="90%" | OutMax | ||
|- | |- | ||
Line 138: | Line 126: | ||
| colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | | colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-f32-icon.png]] - FLOAT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | === | + | ===MapInt=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MapInt''' |
|- | |- | ||
− | | colspan="2" | Map function for | + | | colspan="2" | Map function for signed int type variables |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" | Value | | width="90%" | Value | ||
|- | |- | ||
| colspan="2" | Main variable used for map function | | colspan="2" | Main variable used for map function | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" | InMin | | width="90%" | InMin | ||
|- | |- | ||
| colspan="2" | Lowest input value | | colspan="2" | Lowest input value | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" | InMax | | width="90%" | InMax | ||
|- | |- | ||
| colspan="2" | Highest value input | | colspan="2" | Highest value input | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" | OutMin | | width="90%" | OutMin | ||
|- | |- | ||
| colspan="2" | Lowest value after conversion | | colspan="2" | Lowest value after conversion | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" | OutMax | | width="90%" | OutMax | ||
|- | |- | ||
Line 182: | Line 170: | ||
| colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | | colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 275: | Line 263: | ||
− | === | + | ===MapUlong=== |
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MapUlong''' |
|- | |- | ||
− | | colspan="2" | Map function for | + | | colspan="2" | Map function for unsigned long type variables |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" | Value | | width="90%" | Value | ||
|- | |- | ||
| colspan="2" | Main variable used for map function | | colspan="2" | Main variable used for map function | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" | InMin | | width="90%" | InMin | ||
|- | |- | ||
| colspan="2" | Lowest input value | | colspan="2" | Lowest input value | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" | InMax | | width="90%" | InMax | ||
|- | |- | ||
| colspan="2" | Highest value input | | colspan="2" | Highest value input | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" | OutMin | | width="90%" | OutMin | ||
|- | |- | ||
| colspan="2" | Lowest value after conversion | | colspan="2" | Lowest value after conversion | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" | OutMax | | width="90%" | OutMax | ||
|- | |- | ||
Line 314: | Line 302: | ||
| colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | | colspan="2" | Clamp min & max so result does not go above or below set values. 0=No, 1=Yes | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
Latest revision as of 10:28, 4 March 2024
Author | medelec35 |
Version | 2.0 |
Category | Calculation |
Contents
Map Function component
The map function is intended to change one range of values into another range of values. For example. Output from a temperature sensor is in centigrade. you can map it to give the result in Fahrenheit. To do that set: InMin to 0, InMax 100, OutMin to 32 & OutMax to 212
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Map-Function.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Map-Function.fcfx
Detailed description
No detailed description exists yet for this component
Examples
A simple example showing how to take a value from an adc input with the range 0-255 and mapping this to a predetermined range of 50-150 to drive a PWM output.
Macro reference
MapByte
MapFloat
MapInt
MapLong
MapUInt
MapUlong
Property reference
![]() |
Properties |