<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Scaling</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/4df63fd884/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/4df63fd884/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/4df63fd884/</id><updated>2020-02-27T20:15:44.001000Z</updated><subtitle>Recent posts to Scaling</subtitle><entry><title>Scaling</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/4df63fd884/?limit=25#f70b" rel="alternate"/><published>2020-02-27T20:15:44.001000Z</published><updated>2020-02-27T20:15:44.001000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com79f83584bfa8d7d4e8b87e6e2317f92dc6f69e30</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;This is a linear equation of style y = ax + b.  I will leave you to fill in the blanks on the equation details.&lt;/p&gt;
&lt;p&gt;So create a FUNCTION - but you first need to decide your data type.  INT or REAL... You are using nice rounded numbers, so I will pick INT (using ST language):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;FUNCTION&lt;/span&gt; &lt;span class="nt"&gt;GetDistance&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Raw&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;VAR&lt;/span&gt; &lt;span class="nt"&gt;CONSTANT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;SCALE&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;123&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;OFFSET&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;INT&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;123&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;span class="nt"&gt;GetDistance&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;Raw&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nt"&gt;SCALE&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nt"&gt;OFFSET&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_FUNCTION&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then in your regular program you can simply write:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;Cm&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GetDistance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;HINT:  Always make sure you don't overflow the data type!  INT only goes to +32767.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Scaling</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/4df63fd884/?limit=25#9893" rel="alternate"/><published>2020-02-27T20:15:40.234000Z</published><updated>2020-02-27T20:15:40.234000Z</updated><author><name>Lassera</name><uri>https://forge.codesys.com/u/lassera/</uri></author><id>https://forge.codesys.com2ef539ad403342a251df1b7c1676b9222722c471</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;i am new with programming so i'm asking maybe stupid questions, so if i have analog input what gives value from 400 to 1000.  Value 400 is for example 80 cm and 1000 is 1100cm. How i can make a program which tells automatically how many cm is value 500?Hope somebody understand this...&lt;/p&gt;
&lt;p&gt;thanks&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>