diff --git a/FactoryCalib.py b/FactoryCalib.py
index ca154aa683376a1b7354ca79761263611eb3218b..4de245b08c6e396bc6fa973efaad4942bd92ecdc 100644
--- a/FactoryCalib.py
+++ b/FactoryCalib.py
@@ -2,6 +2,7 @@ import threading
 
 from lib.Axes1Ref import *
 from lib.Axes2Ref import *
+from lib.ColorCalib import *
 from lib.controller import *
 from lib.display import *
 from lib.DPS import *
diff --git a/lib/ColorCalib.blockly b/lib/ColorCalib.blockly
new file mode 100644
index 0000000000000000000000000000000000000000..808c75d2aa87e3b261adcc089676a8649f58e4bf
--- /dev/null
+++ b/lib/ColorCalib.blockly
@@ -0,0 +1,214 @@
+<xml xmlns="https://developers.google.com/blockly/xml" version="14">
+  <variables>
+    <variable id="2hXKDa]i2lK78Fcn!kS7">v</variable>
+    <variable id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</variable>
+    <variable id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</variable>
+    <variable id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</variable>
+    <variable id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</variable>
+    <variable id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</variable>
+  </variables>
+  <block type="util_python_imports" id="x9R(,!yKv%F:*-v(S5F)" x="0" y="0">
+    <field name="value">import logging</field>
+  </block>
+  <block type="procedures_defnoreturn" id="VSmATTY?.L[C{f,=c#1:" x="0" y="103">
+    <mutation>
+      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="I@B?}jt30*H/Nrzr)p2."/>
+    </mutation>
+    <field name="NAME">set_calibvalue_white</field>
+    <field name="I@B?}jt30*H/Nrzr)p2.">v</field>
+    <statement name="STACK">
+      <block type="variables_set" id="a${YCHPG(AjwADE3zHI6">
+        <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
+        <value name="VALUE">
+          <block type="variables_get" id="p=~K_g5Zv**:PM^83o6H">
+            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
+          </block>
+        </value>
+      </block>
+    </statement>
+  </block>
+  <block type="procedures_defnoreturn" id="(h]YqJ@0g{:(ai*WF@?!" x="0" y="243">
+    <mutation>
+      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="`,@l)KD{{wbrC!|u;.cC"/>
+    </mutation>
+    <field name="NAME">set_calibvalue_red</field>
+    <field name="`,@l)KD{{wbrC!|u;.cC">v</field>
+    <statement name="STACK">
+      <block type="variables_set" id="BBa*zP(r{37tQcU/Kxn?">
+        <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
+        <value name="VALUE">
+          <block type="variables_get" id="3jiT1mXL`X+gHmxkobxF">
+            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
+          </block>
+        </value>
+      </block>
+    </statement>
+  </block>
+  <block type="procedures_defnoreturn" id="L]1+4A^?Yt^]vOcR=Sf5" x="0" y="383">
+    <mutation>
+      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="|#3L}sF}`~w2aK|mn7._"/>
+    </mutation>
+    <field name="NAME">set_calibvalue_blue</field>
+    <field name="|#3L}sF}`~w2aK|mn7._">v</field>
+    <statement name="STACK">
+      <block type="variables_set" id="?MM-tl:E%H)cVd;-8OqZ">
+        <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
+        <value name="VALUE">
+          <block type="variables_get" id="DeVn})_ksw.U{m1th0;0">
+            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
+          </block>
+        </value>
+      </block>
+    </statement>
+  </block>
+  <block type="procedures_defreturn" id="cYBcy|]-F?s-:oG+Ch0Q" x="0" y="523">
+    <field name="NAME">get_calibvalue_list</field>
+    <value name="RETURN">
+      <block type="lists_create_with" id="@$jB[eQO!ql}q5LGgpF9">
+        <mutation items="3"/>
+        <value name="ADD0">
+          <block type="variables_get" id="V#st)gBU=4!v,6j5Zr0z">
+            <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
+          </block>
+        </value>
+        <value name="ADD1">
+          <block type="variables_get" id="P8NBkGe1!xnMK]Kx|?,h">
+            <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
+          </block>
+        </value>
+        <value name="ADD2">
+          <block type="variables_get" id="gCp5RVPDngcJSq.J3;^U">
+            <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
+          </block>
+        </value>
+      </block>
+    </value>
+  </block>
+  <block type="procedures_defnoreturn" id="By#/eOVl{%tWXHnq;[t8" x="0" y="702">
+    <mutation>
+      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid=",],|#/r)~Xl=JL*8taHJ"/>
+    </mutation>
+    <field name="NAME">set_thresh_white_red</field>
+    <field name=",],|#/r)~Xl=JL*8taHJ">v</field>
+    <statement name="STACK">
+      <block type="variables_set" id="UD+uDG:i:wX*)5qZ@^}{">
+        <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
+        <value name="VALUE">
+          <block type="variables_get" id="bRmRH4D6Oi=R]PPIe,e*">
+            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
+          </block>
+        </value>
+      </block>
+    </statement>
+  </block>
+  <block type="procedures_defnoreturn" id="Z!dZf*!e$c:zz,}xl0R~" x="0" y="842">
+    <mutation>
+      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="Nz7/7d0Ek!?Vdf4NY1ae"/>
+    </mutation>
+    <field name="NAME">set_thresh_red_blue</field>
+    <field name="Nz7/7d0Ek!?Vdf4NY1ae">v</field>
+    <statement name="STACK">
+      <block type="variables_set" id="-OcEtX|C/9dSL#-,18]v">
+        <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
+        <value name="VALUE">
+          <block type="variables_get" id="bWou2ch7.W|QJQY[2VOJ">
+            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
+          </block>
+        </value>
+      </block>
+    </statement>
+  </block>
+  <block type="procedures_defreturn" id="3{p]h$WzxQ#8708wyjj:" x="0" y="982">
+    <field name="NAME">get_thresh_list</field>
+    <value name="RETURN">
+      <block type="lists_create_with" id="_,dzXWzP31K6}|b;j]]-">
+        <mutation items="2"/>
+        <value name="ADD0">
+          <block type="variables_get" id="ug`[1g-@%4/SjaYx4}NK">
+            <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
+          </block>
+        </value>
+        <value name="ADD1">
+          <block type="variables_get" id="EbxSGe}4-]w[}8NI8Fa}">
+            <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
+          </block>
+        </value>
+      </block>
+    </value>
+  </block>
+  <block type="procedures_defnoreturn" id="G(e53s]+_0LtKYhM25sz" x="0" y="1132">
+    <field name="NAME">calculate_thresh</field>
+    <statement name="STACK">
+      <block type="variables_set" id="_*=Fb*]_gOn_Lz8Sfioz">
+        <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
+        <value name="VALUE">
+          <block type="math_round" id="]NG|19#7?B^?/jS1O}KV">
+            <field name="OP">ROUND</field>
+            <field name="DECIMALS">0</field>
+            <value name="NUM">
+              <block type="math_arithmetic" id="U^ALKK03f|sdoI32b1+{">
+                <field name="OP">DIVIDE</field>
+                <value name="A">
+                  <block type="math_arithmetic" id="5XFO~B:[o[C9ZOF|Zeq*">
+                    <field name="OP">ADD</field>
+                    <value name="A">
+                      <block type="variables_get" id="XoDs~!=~yCdr~.Y/]h,-">
+                        <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
+                      </block>
+                    </value>
+                    <value name="B">
+                      <block type="variables_get" id="%kKzq$jcq0n=C5|M])4D">
+                        <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
+                      </block>
+                    </value>
+                  </block>
+                </value>
+                <value name="B">
+                  <block type="math_number" id="qwgU^#:ajwc4JS_SsD}[">
+                    <field name="NUM">2</field>
+                  </block>
+                </value>
+              </block>
+            </value>
+          </block>
+        </value>
+        <next>
+          <block type="variables_set" id="yp`a}#gO/DclN@aT1*-m">
+            <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
+            <value name="VALUE">
+              <block type="math_round" id="Eq1uHC2-adQSHRfTiRQ!">
+                <field name="OP">ROUND</field>
+                <field name="DECIMALS">0</field>
+                <value name="NUM">
+                  <block type="math_arithmetic" id="el*K!Elt+,MePUqAP1JA">
+                    <field name="OP">DIVIDE</field>
+                    <value name="A">
+                      <block type="math_arithmetic" id="b.yA5V#fe3MGn~b^_P3A">
+                        <field name="OP">ADD</field>
+                        <value name="A">
+                          <block type="variables_get" id="o(my3Un1G.N:2E;H(mO{">
+                            <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
+                          </block>
+                        </value>
+                        <value name="B">
+                          <block type="variables_get" id="Ow%Zf1rOO0*}|UYk#{uY">
+                            <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
+                          </block>
+                        </value>
+                      </block>
+                    </value>
+                    <value name="B">
+                      <block type="math_number" id=")}d.#^Fx=$r[SAo02Np=">
+                        <field name="NUM">2</field>
+                      </block>
+                    </value>
+                  </block>
+                </value>
+              </block>
+            </value>
+          </block>
+        </next>
+      </block>
+    </statement>
+  </block>
+</xml>
\ No newline at end of file
diff --git a/lib/ColorCalib.py b/lib/ColorCalib.py
new file mode 100644
index 0000000000000000000000000000000000000000..44e482e3cff6607450401f2af101e16a5a68ae10
--- /dev/null
+++ b/lib/ColorCalib.py
@@ -0,0 +1,52 @@
+import logging
+import math
+
+v = None
+calibvalue_white = None
+calibvalue_red = None
+calibvalue_blue = None
+thresh_white_red = None
+thresh_red_blue = None
+
+
+def set_calibvalue_white(v):
+    global calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    calibvalue_white = v
+
+
+def set_calibvalue_red(v):
+    global calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    calibvalue_red = v
+
+
+def set_calibvalue_blue(v):
+    global calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    calibvalue_blue = v
+
+
+def get_calibvalue_list():
+    global v, calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    return [calibvalue_white, calibvalue_red, calibvalue_blue]
+
+
+def set_thresh_white_red(v):
+    global calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    thresh_white_red = v
+
+
+def set_thresh_red_blue(v):
+    global calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    thresh_red_blue = v
+
+
+def get_thresh_list():
+    global v, calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    return [thresh_white_red, thresh_red_blue]
+
+
+def calculate_thresh():
+    global v, calibvalue_white, calibvalue_red, calibvalue_blue, thresh_white_red, thresh_red_blue
+    thresh_white_red = round((calibvalue_white + calibvalue_red) / 2)
+    thresh_red_blue = round((calibvalue_red + calibvalue_blue) / 2)
+
+
diff --git a/lib/NodeRED.blockly b/lib/NodeRED.blockly
index c6cac11ca555c6d723bd7e22270aeac00d479e22..9ee9d23e86bf3b172b146cf10ebb856e04165029 100644
--- a/lib/NodeRED.blockly
+++ b/lib/NodeRED.blockly
@@ -15,7 +15,14 @@
     <variable id="gE_}aCN*#~^yOmZlqKv9">gtyp_Setup_x_Color_Sensor_Calibration</variable>
     <variable id="cTcpwCvGLYg4_[qJf{CM">state_positioning</variable>
     <variable id=")XfA{xXx7sN)MA=qSY=H">gtyp_Setup_i_Color_Sensor_Selection</variable>
+    <variable id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</variable>
+    <variable id="aQ:d%c!ilWYQz|GZ5N0~">gtyp_Setup_w_Threshold_White_Red</variable>
+    <variable id="A{`)A3~(6e.5r^y~X;S1">gtyp_Setup_w_Threshold_Red_Blue</variable>
+    <variable id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</variable>
     <variable id="1R^uniMizt=l7#?^bm$c">gtyp_Setup_di_Pos_Rotate</variable>
+    <variable id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</variable>
+    <variable id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</variable>
+    <variable id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</variable>
     <variable id="mvCEZ!N=009NymF/qM7c">gtyp_Setup_di_Pos_Vertical</variable>
     <variable id="SxENFYiA)D/cgAH0A!|E">ts</variable>
     <variable id="5A|5#!$f-*CkU%!}@r8|">controller_name</variable>
@@ -920,6 +927,62 @@
             <statement name="DO6">
               <block type="util_python" id="EjcMbne,uWHepJJD]0;S" inline="true">
                 <field name="value">logging.debug('blue')</field>
+                <next>
+                  <block type="import_function_noreturn" id="YCRDr7WukPJ%!E$EdeWD" inline="true">
+                    <mutation parentId="L]1+4A^?Yt^]vOcR=Sf5"/>
+                    <field name="name">set_calibvalue_blue</field>
+                    <data>L]1+4A^?Yt^]vOcR=Sf5</data>
+                    <value name="v">
+                      <block type="variables_get" id="@nh:j9PUv!EhZ+[?3YWh">
+                        <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                      </block>
+                    </value>
+                    <next>
+                      <block type="mqtt_publish" id="J*R4]^bY/[YhE+K_U[,L">
+                        <value name="name">
+                          <block type="variables_get" id="f`hJ(mAa#}?en]xMnue}">
+                            <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                          </block>
+                        </value>
+                        <value name="topic">
+                          <shadow type="text" id="wyi2v$=T|AR~jbBrO;y*">
+                            <field name="TEXT">gtyp_Setup/w_Calib_ColorValue_Blue</field>
+                          </shadow>
+                        </value>
+                        <value name="value">
+                          <shadow type="logic_null" id="=PQt#:{d:(%qr].z$Kr]"/>
+                          <block type="lists_getIndex" id="*@1lfgIeU%6v?IRroU#U">
+                            <mutation statement="false" at="true"/>
+                            <field name="MODE">GET</field>
+                            <field name="WHERE">FROM_START</field>
+                            <value name="VALUE">
+                              <block type="import_function_return" id="TorF}9uL0!9|@tV3N]03">
+                                <mutation parentId="cYBcy|]-F?s-:oG+Ch0Q"/>
+                                <field name="name">get_calibvalue_list</field>
+                                <data>cYBcy|]-F?s-:oG+Ch0Q</data>
+                              </block>
+                            </value>
+                            <value name="AT">
+                              <block type="math_number" id="Uu3d~buP:pcp%2Nmt5hV">
+                                <field name="NUM">3</field>
+                              </block>
+                            </value>
+                          </block>
+                        </value>
+                        <value name="qos">
+                          <shadow type="math_number" id="lf$.[u4_4mhd$Ry!Ud{r">
+                            <field name="NUM">2</field>
+                          </shadow>
+                        </value>
+                        <value name="retain">
+                          <shadow type="logic_boolean" id="]R~eNWe512AQl4{2b`a,">
+                            <field name="BOOL">FALSE</field>
+                          </shadow>
+                        </value>
+                      </block>
+                    </next>
+                  </block>
+                </next>
               </block>
             </statement>
             <value name="IF7">
@@ -940,6 +1003,62 @@
             <statement name="DO7">
               <block type="util_python" id="dh+?W4scKeSTCJpcAH@c" inline="true">
                 <field name="value">logging.debug('red')</field>
+                <next>
+                  <block type="import_function_noreturn" id="s;#Z.pH%%q!%*`m=h)Nn" inline="true">
+                    <mutation parentId="(h]YqJ@0g{:(ai*WF@?!"/>
+                    <field name="name">set_calibvalue_red</field>
+                    <data>(h]YqJ@0g{:(ai*WF@?!</data>
+                    <value name="v">
+                      <block type="variables_get" id="rm2z-Yj!}L{(F:Q::V|/">
+                        <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                      </block>
+                    </value>
+                    <next>
+                      <block type="mqtt_publish" id="jMog#uYS@M1?.gTV}L-6">
+                        <value name="name">
+                          <block type="variables_get" id="zZ:zH_7J-W1Keqej4u#;">
+                            <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                          </block>
+                        </value>
+                        <value name="topic">
+                          <shadow type="text" id=")x9GUXi5dg06^+w=[HTa">
+                            <field name="TEXT">gtyp_Setup/w_Calib_ColorValue_Red</field>
+                          </shadow>
+                        </value>
+                        <value name="value">
+                          <shadow type="logic_null"/>
+                          <block type="lists_getIndex" id="rY{Z)crg6Neb*u/=M_Bo">
+                            <mutation statement="false" at="true"/>
+                            <field name="MODE">GET</field>
+                            <field name="WHERE">FROM_START</field>
+                            <value name="VALUE">
+                              <block type="import_function_return" id="{[skK2A),9|oF0hNCaR3">
+                                <mutation parentId="cYBcy|]-F?s-:oG+Ch0Q"/>
+                                <field name="name">get_calibvalue_list</field>
+                                <data>cYBcy|]-F?s-:oG+Ch0Q</data>
+                              </block>
+                            </value>
+                            <value name="AT">
+                              <block type="math_number" id="Z|myw},b|9KVw]iB.,c#">
+                                <field name="NUM">2</field>
+                              </block>
+                            </value>
+                          </block>
+                        </value>
+                        <value name="qos">
+                          <shadow type="math_number" id="/m_^6L=q3CuUy[}VM|zp">
+                            <field name="NUM">2</field>
+                          </shadow>
+                        </value>
+                        <value name="retain">
+                          <shadow type="logic_boolean" id="GY88]0o9G(iF.MoDNs[~">
+                            <field name="BOOL">FALSE</field>
+                          </shadow>
+                        </value>
+                      </block>
+                    </next>
+                  </block>
+                </next>
               </block>
             </statement>
             <value name="IF8">
@@ -960,6 +1079,62 @@
             <statement name="DO8">
               <block type="util_python" id="cal$r@Hy,n3W)x}(%B-a" inline="true">
                 <field name="value">logging.debug('white')</field>
+                <next>
+                  <block type="import_function_noreturn" id="u0c*`vN#@TZ7[50Gi.3I" inline="true">
+                    <mutation parentId="VSmATTY?.L[C{f,=c#1:"/>
+                    <field name="name">set_calibvalue_white</field>
+                    <data>VSmATTY?.L[C{f,=c#1:</data>
+                    <value name="v">
+                      <block type="variables_get" id="Aa5O$./;N,;Sq~r*bZ/7">
+                        <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                      </block>
+                    </value>
+                    <next>
+                      <block type="mqtt_publish" id="oPTA0oQXW0tvm[APyACg">
+                        <value name="name">
+                          <block type="variables_get" id="@}9)CPN{s_j$C{Y6pH~a">
+                            <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                          </block>
+                        </value>
+                        <value name="topic">
+                          <shadow type="text" id="6,Y5baUAPi7w4OBf*mBm">
+                            <field name="TEXT">gtyp_Setup/w_Calib_ColorValue_White</field>
+                          </shadow>
+                        </value>
+                        <value name="value">
+                          <shadow type="logic_null"/>
+                          <block type="lists_getIndex" id="/y0n-e[7zqy7acn6giys">
+                            <mutation statement="false" at="true"/>
+                            <field name="MODE">GET</field>
+                            <field name="WHERE">FROM_START</field>
+                            <value name="VALUE">
+                              <block type="import_function_return" id="t?C{uExU9MrBx8(4oZij">
+                                <mutation parentId="cYBcy|]-F?s-:oG+Ch0Q"/>
+                                <field name="name">get_calibvalue_list</field>
+                                <data>cYBcy|]-F?s-:oG+Ch0Q</data>
+                              </block>
+                            </value>
+                            <value name="AT">
+                              <block type="math_number" id="l)yfEY%_%@kpnA}{jzO8">
+                                <field name="NUM">1</field>
+                              </block>
+                            </value>
+                          </block>
+                        </value>
+                        <value name="qos">
+                          <shadow type="math_number" id="Za9uc*LZ`Sa0BZp9}B7M">
+                            <field name="NUM">2</field>
+                          </shadow>
+                        </value>
+                        <value name="retain">
+                          <shadow type="logic_boolean" id="M^)|Z`3lIBWO_WR#y}9b">
+                            <field name="BOOL">FALSE</field>
+                          </shadow>
+                        </value>
+                      </block>
+                    </next>
+                  </block>
+                </next>
               </block>
             </statement>
             <value name="IF9">
@@ -980,6 +1155,121 @@
             <statement name="DO9">
               <block type="util_python" id="BR2#!(.cXKq5`b-S1e6*" inline="true">
                 <field name="value">logging.debug('calculate')</field>
+                <next>
+                  <block type="import_function_noreturn" id="$rm~6Epv|%q`[N6$iQf#">
+                    <mutation parentId="G(e53s]+_0LtKYhM25sz"/>
+                    <field name="name">calculate_thresh</field>
+                    <data>G(e53s]+_0LtKYhM25sz</data>
+                    <next>
+                      <block type="variables_set" id="owyA%mgF1RCO2iRq.$_T">
+                        <field name="VAR" id="aQ:d%c!ilWYQz|GZ5N0~">gtyp_Setup_w_Threshold_White_Red</field>
+                        <value name="VALUE">
+                          <block type="lists_getIndex" id=";yVZ(Cw]`X12U|F,6[qf">
+                            <mutation statement="false" at="true"/>
+                            <field name="MODE">GET</field>
+                            <field name="WHERE">FROM_START</field>
+                            <value name="VALUE">
+                              <block type="import_function_return" id="s3ZH#P/gI7K_WK-jYUB|">
+                                <mutation parentId="3{p]h$WzxQ#8708wyjj:"/>
+                                <field name="name">get_thresh_list</field>
+                                <data>3{p]h$WzxQ#8708wyjj:</data>
+                              </block>
+                            </value>
+                            <value name="AT">
+                              <block type="math_number" id="+Ags6xEWMkUbh-;#([-,">
+                                <field name="NUM">1</field>
+                              </block>
+                            </value>
+                          </block>
+                        </value>
+                        <next>
+                          <block type="variables_set" id="ukNju^(BbteJl)rzL@CD">
+                            <field name="VAR" id="A{`)A3~(6e.5r^y~X;S1">gtyp_Setup_w_Threshold_Red_Blue</field>
+                            <value name="VALUE">
+                              <block type="lists_getIndex" id="Avm(~7TU_I|aYgCMSl;z">
+                                <mutation statement="false" at="true"/>
+                                <field name="MODE">GET</field>
+                                <field name="WHERE">FROM_START</field>
+                                <value name="VALUE">
+                                  <block type="import_function_return" id="p7?yQH~}a@r-YWrFTo^Y">
+                                    <mutation parentId="3{p]h$WzxQ#8708wyjj:"/>
+                                    <field name="name">get_thresh_list</field>
+                                    <data>3{p]h$WzxQ#8708wyjj:</data>
+                                  </block>
+                                </value>
+                                <value name="AT">
+                                  <block type="math_number" id="B%J)?ZKYbhas9~_0kMlX">
+                                    <field name="NUM">2</field>
+                                  </block>
+                                </value>
+                              </block>
+                            </value>
+                            <next>
+                              <block type="mqtt_publish" id="2xw~znw/rcJeew?IQFi~">
+                                <value name="name">
+                                  <block type="variables_get" id="$.JU`bI^+l.Tt%`1EP}O">
+                                    <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                  </block>
+                                </value>
+                                <value name="topic">
+                                  <shadow type="text" id="MC([5IG#9,_T;J]YJc:k">
+                                    <field name="TEXT">gtyp_Setup/w_Threshold_White_Red</field>
+                                  </shadow>
+                                </value>
+                                <value name="value">
+                                  <shadow type="logic_null" id="Gg%fz!}Xj4myT?v6%UCj"/>
+                                  <block type="variables_get" id="KH(L/#[r:Izg}BD2v2GU">
+                                    <field name="VAR" id="aQ:d%c!ilWYQz|GZ5N0~">gtyp_Setup_w_Threshold_White_Red</field>
+                                  </block>
+                                </value>
+                                <value name="qos">
+                                  <shadow type="math_number" id="!:L|Ky;L]$zA]`=P*H{r">
+                                    <field name="NUM">2</field>
+                                  </shadow>
+                                </value>
+                                <value name="retain">
+                                  <shadow type="logic_boolean" id="0?[Wg^^Y-zBitceH!qvu">
+                                    <field name="BOOL">FALSE</field>
+                                  </shadow>
+                                </value>
+                                <next>
+                                  <block type="mqtt_publish" id="a-)+%8KXIoQ9h#0BQz4m">
+                                    <value name="name">
+                                      <block type="variables_get" id="Gre0:W11~KN.}M%E+@@%">
+                                        <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                      </block>
+                                    </value>
+                                    <value name="topic">
+                                      <shadow type="text" id="?p1C=(P;p*SxBbP},lF}">
+                                        <field name="TEXT">gtyp_Setup/w_Threshold_Red_Blue</field>
+                                      </shadow>
+                                    </value>
+                                    <value name="value">
+                                      <shadow type="logic_null"/>
+                                      <block type="variables_get" id="z[uIeYv35xU=Ua0,XnBh">
+                                        <field name="VAR" id="A{`)A3~(6e.5r^y~X;S1">gtyp_Setup_w_Threshold_Red_Blue</field>
+                                      </block>
+                                    </value>
+                                    <value name="qos">
+                                      <shadow type="math_number" id="xmlIJ*ZeGemP;-ZEa}s8">
+                                        <field name="NUM">2</field>
+                                      </shadow>
+                                    </value>
+                                    <value name="retain">
+                                      <shadow type="logic_boolean" id="-O6^;@ouwK~r#jd]n|Bj">
+                                        <field name="BOOL">FALSE</field>
+                                      </shadow>
+                                    </value>
+                                  </block>
+                                </next>
+                              </block>
+                            </next>
+                          </block>
+                        </next>
+                      </block>
+                    </next>
+                  </block>
+                </next>
               </block>
             </statement>
             <value name="IF10">
@@ -1066,6 +1356,16 @@
                                     <field name="BOOL">FALSE</field>
                                   </shadow>
                                 </value>
+                                <next>
+                                  <block type="variables_set" id="vXAx(Pb*x]r=o-4.qC%0">
+                                    <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                                    <value name="VALUE">
+                                      <block type="math_number" id="5-t#[D4E/P?};Vyf1Q1I">
+                                        <field name="NUM">0</field>
+                                      </block>
+                                    </value>
+                                  </block>
+                                </next>
                               </block>
                             </next>
                           </block>
@@ -1130,6 +1430,72 @@
                         <statement name="DO0">
                           <block type="util_python" id="B0@44dFH@l?Wmn}!?8@U" inline="true">
                             <field name="value">logging.debug('1')</field>
+                            <next>
+                              <block type="variables_set" id="BPg6vOMOI?;C`6A+QJsT">
+                                <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                                <value name="VALUE">
+                                  <block type="math_round" id="5Z4z]JtJXR~%c^j)XFcq">
+                                    <field name="OP">ROUND</field>
+                                    <field name="DECIMALS">0</field>
+                                    <value name="NUM">
+                                      <block type="import_function_return" id="oJ7BxBI@76/r%%ru?)v}">
+                                        <mutation parentId="$]uSxm9]*Qu3iZl~w~MW"/>
+                                        <field name="name">readColorValue</field>
+                                        <data>$]uSxm9]*Qu3iZl~w~MW</data>
+                                      </block>
+                                    </value>
+                                  </block>
+                                </value>
+                                <next>
+                                  <block type="variables_set" id="1Jy`?Na^yUC3;Z|gB3c7">
+                                    <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field>
+                                    <value name="VALUE">
+                                      <block type="lists_getIndex" id="~fs!uVi1E8lRO)4=5;z[">
+                                        <mutation statement="false" at="true"/>
+                                        <field name="MODE">GET</field>
+                                        <field name="WHERE">FROM_START</field>
+                                        <value name="VALUE">
+                                          <block type="import_function_return" id="}Q-$}6fTF1GYJT1Po,K,">
+                                            <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/>
+                                            <field name="name">get_calib_data_SLD</field>
+                                            <data>b|1;0mU=wNNO2Ry{f6,Z</data>
+                                          </block>
+                                        </value>
+                                        <value name="AT">
+                                          <block type="math_number" id="amR(f,!]|GX_?d]8_w:.">
+                                            <field name="NUM">1</field>
+                                          </block>
+                                        </value>
+                                      </block>
+                                    </value>
+                                    <next>
+                                      <block type="variables_set" id="7W9V2j6i4OTDkbN?9g~C">
+                                        <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field>
+                                        <value name="VALUE">
+                                          <block type="lists_getIndex" id="jgWLl%?ue-EK/xR2IF7X">
+                                            <mutation statement="false" at="true"/>
+                                            <field name="MODE">GET</field>
+                                            <field name="WHERE">FROM_START</field>
+                                            <value name="VALUE">
+                                              <block type="import_function_return" id="NgJyh*u),a?oiws6P3Ve">
+                                                <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/>
+                                                <field name="name">get_calib_data_SLD</field>
+                                                <data>b|1;0mU=wNNO2Ry{f6,Z</data>
+                                              </block>
+                                            </value>
+                                            <value name="AT">
+                                              <block type="math_number" id="{e+d,:6:KIfmj|nsK,LV">
+                                                <field name="NUM">2</field>
+                                              </block>
+                                            </value>
+                                          </block>
+                                        </value>
+                                      </block>
+                                    </next>
+                                  </block>
+                                </next>
+                              </block>
+                            </next>
                           </block>
                         </statement>
                         <value name="IF1">
@@ -1150,13 +1516,273 @@
                         <statement name="DO1">
                           <block type="util_python" id="r|k1IWqLgp1fm#phq8rp" inline="true">
                             <field name="value">logging.debug('2')</field>
+                            <next>
+                              <block type="variables_set" id="9*`+]6N]2vvRh5r{)qUZ">
+                                <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                                <value name="VALUE">
+                                  <block type="import_function_return" id="dcG_(9Wi^pI2:{/h0uN?">
+                                    <mutation parentId="![`j=,+%Mnlx`Drv~HID"/>
+                                    <field name="name">readDPSColorValue</field>
+                                    <data>![`j=,+%Mnlx`Drv~HID</data>
+                                  </block>
+                                </value>
+                                <next>
+                                  <block type="variables_set" id="!Oq+x$%5d+!s%GW^IL1)">
+                                    <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field>
+                                    <value name="VALUE">
+                                      <block type="lists_getIndex" id=":5TIrIqi]}Xb}jT@l$*w">
+                                        <mutation statement="false" at="true"/>
+                                        <field name="MODE">GET</field>
+                                        <field name="WHERE">FROM_START</field>
+                                        <value name="VALUE">
+                                          <block type="import_function_return" id="h!xFYCh(nNmH9sqSAI$I">
+                                            <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/>
+                                            <field name="name">get_calib_data_DPS</field>
+                                            <data>Q9p7dhe-|x*[t`L^}||B</data>
+                                          </block>
+                                        </value>
+                                        <value name="AT">
+                                          <block type="math_number" id="a,{!zAt=;F22-Yz8L!CI">
+                                            <field name="NUM">1</field>
+                                          </block>
+                                        </value>
+                                      </block>
+                                    </value>
+                                    <next>
+                                      <block type="variables_set" id="`DHgbw8C:@@@VX1-ZfUz">
+                                        <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field>
+                                        <value name="VALUE">
+                                          <block type="lists_getIndex" id="ydb%=g-IQpfs)69]XP$a">
+                                            <mutation statement="false" at="true"/>
+                                            <field name="MODE">GET</field>
+                                            <field name="WHERE">FROM_START</field>
+                                            <value name="VALUE">
+                                              <block type="import_function_return" id=".Z=/O/yxPs..1ytF/wXZ">
+                                                <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/>
+                                                <field name="name">get_calib_data_DPS</field>
+                                                <data>Q9p7dhe-|x*[t`L^}||B</data>
+                                              </block>
+                                            </value>
+                                            <value name="AT">
+                                              <block type="math_number" id="uIk7]pVcrtg=,ua0zVPi">
+                                                <field name="NUM">2</field>
+                                              </block>
+                                            </value>
+                                          </block>
+                                        </value>
+                                      </block>
+                                    </next>
+                                  </block>
+                                </next>
+                              </block>
+                            </next>
                           </block>
                         </statement>
                         <statement name="ELSE">
                           <block type="util_python" id="rWWm)}Q.WvYJz$62-AC:" inline="true">
                             <field name="value">logging.debug('none')</field>
+                            <next>
+                              <block type="variables_set" id="9x5:lZLpAx9wmr9(j=_s">
+                                <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field>
+                                <value name="VALUE">
+                                  <block type="math_number" id="gz]b+,C1~FgTaNK~=r,5">
+                                    <field name="NUM">0</field>
+                                  </block>
+                                </value>
+                                <next>
+                                  <block type="variables_set" id="S2G]dx)f~jgzuW0k^kNp">
+                                    <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field>
+                                    <value name="VALUE">
+                                      <block type="math_number" id="C=d/[ap2uVxKy:e^MI:Z">
+                                        <field name="NUM">0</field>
+                                      </block>
+                                    </value>
+                                    <next>
+                                      <block type="variables_set" id="K8LkNm#7hFX|dJ!z6$7i">
+                                        <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field>
+                                        <value name="VALUE">
+                                          <block type="math_number" id="ke^5kEWYDF/S$ln@)=%_">
+                                            <field name="NUM">0</field>
+                                          </block>
+                                        </value>
+                                        <next>
+                                          <block type="variables_set" id="=~039uS6s1=!E3E6zijO">
+                                            <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field>
+                                            <value name="VALUE">
+                                              <block type="math_number" id="s(Z7II`Fld+4)J.OPb9T">
+                                                <field name="NUM">0</field>
+                                              </block>
+                                            </value>
+                                            <next>
+                                              <block type="variables_set" id="g)-8V^Z,Zx{V:R_f]i_.">
+                                                <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                                                <value name="VALUE">
+                                                  <block type="math_number" id="Gof8u):q_v1H]SGYCc7y">
+                                                    <field name="NUM">0</field>
+                                                  </block>
+                                                </value>
+                                              </block>
+                                            </next>
+                                          </block>
+                                        </next>
+                                      </block>
+                                    </next>
+                                  </block>
+                                </next>
+                              </block>
+                            </next>
                           </block>
                         </statement>
+                        <next>
+                          <block type="mqtt_publish" id="x,T;`pWHXbo87!Rvm0G`">
+                            <value name="name">
+                              <block type="variables_get" id="i{O?M+Ri-ZE?KAY-X*:O">
+                                <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                              </block>
+                            </value>
+                            <value name="topic">
+                              <shadow type="text" id="LR9uuA$)sP[%^NTy0HFw">
+                                <field name="TEXT">gtyp_Setup/w_Actual_ColorValue</field>
+                              </shadow>
+                            </value>
+                            <value name="value">
+                              <shadow type="logic_null" id="yj8b%%[6em;{+Ec*l(IJ"/>
+                              <block type="variables_get" id="DK#4,,B,e()PG{h$I8Y0">
+                                <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field>
+                              </block>
+                            </value>
+                            <value name="qos">
+                              <shadow type="math_number" id="^7R#[u$F*-SU8B**H/@S">
+                                <field name="NUM">2</field>
+                              </shadow>
+                            </value>
+                            <value name="retain">
+                              <shadow type="logic_boolean" id="uk;Mv7J@HAYh#UU(xK4J">
+                                <field name="BOOL">FALSE</field>
+                              </shadow>
+                            </value>
+                            <next>
+                              <block type="mqtt_publish" id="Tr6*L5MmGUw.AvHyamY1">
+                                <value name="name">
+                                  <block type="variables_get" id="WCtWefm``a=@t.FvV6Ac">
+                                    <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                  </block>
+                                </value>
+                                <value name="topic">
+                                  <shadow type="text" id="F]G-gNlf!`e_U_qdumeE">
+                                    <field name="TEXT">gtyp_SLD/w_Threshold_White_Red</field>
+                                  </shadow>
+                                </value>
+                                <value name="value">
+                                  <shadow type="logic_null"/>
+                                  <block type="variables_get" id="CA*7dY|3*S+0`O#yh$UV">
+                                    <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field>
+                                  </block>
+                                </value>
+                                <value name="qos">
+                                  <shadow type="math_number" id="V-RWpnm?!B]u{GqNJAg$">
+                                    <field name="NUM">2</field>
+                                  </shadow>
+                                </value>
+                                <value name="retain">
+                                  <shadow type="logic_boolean" id="=RK^F}d7d^E_mU*W(1}S">
+                                    <field name="BOOL">FALSE</field>
+                                  </shadow>
+                                </value>
+                                <next>
+                                  <block type="mqtt_publish" id="E=2htASUa2V7[.Oh1Z~g">
+                                    <value name="name">
+                                      <block type="variables_get" id="E=].S3E:1;mEJj~=9fb+">
+                                        <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                      </block>
+                                    </value>
+                                    <value name="topic">
+                                      <shadow type="text" id="1=udhKnD|L.;~2$e^_#_">
+                                        <field name="TEXT">gtyp_SLD/w_Threshold_Red_Blue</field>
+                                      </shadow>
+                                    </value>
+                                    <value name="value">
+                                      <shadow type="logic_null"/>
+                                      <block type="variables_get" id="~}pnCIq5Q%wF4(fA0fsq">
+                                        <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field>
+                                      </block>
+                                    </value>
+                                    <value name="qos">
+                                      <shadow type="math_number" id="E4b)TY}~jy~SgWRG28:A">
+                                        <field name="NUM">2</field>
+                                      </shadow>
+                                    </value>
+                                    <value name="retain">
+                                      <shadow type="logic_boolean" id="pQnV]dxl4;W):A3rbTA4">
+                                        <field name="BOOL">FALSE</field>
+                                      </shadow>
+                                    </value>
+                                    <next>
+                                      <block type="mqtt_publish" id="]+EFhfc|)bE:M?s~.ngZ">
+                                        <value name="name">
+                                          <block type="variables_get" id="/rhX}@]}|@N.dEfulb@p">
+                                            <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                          </block>
+                                        </value>
+                                        <value name="topic">
+                                          <shadow type="text" id=";//4DTrS)DM6*idO;]QU">
+                                            <field name="TEXT">gtyp_SSC/w_Threshold_White_Red</field>
+                                          </shadow>
+                                        </value>
+                                        <value name="value">
+                                          <shadow type="logic_null"/>
+                                          <block type="variables_get" id="PJ+D)]FK6=D!^WDu/Z|5">
+                                            <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field>
+                                          </block>
+                                        </value>
+                                        <value name="qos">
+                                          <shadow type="math_number" id="XROfsH:uPwEr;=?ZA2BH">
+                                            <field name="NUM">2</field>
+                                          </shadow>
+                                        </value>
+                                        <value name="retain">
+                                          <shadow type="logic_boolean" id="60}wRHbBKjeDf|]~O*k`">
+                                            <field name="BOOL">FALSE</field>
+                                          </shadow>
+                                        </value>
+                                        <next>
+                                          <block type="mqtt_publish" id="FME^shM?U!h!^!cby}W+">
+                                            <value name="name">
+                                              <block type="variables_get" id="SWRJBMR,KRCD#rU;5]k_">
+                                                <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field>
+                                              </block>
+                                            </value>
+                                            <value name="topic">
+                                              <shadow type="text" id="7H2q)ld@nos)0D@g-ST{">
+                                                <field name="TEXT">gtyp_SSC/w_Threshold_Red_Blue</field>
+                                              </shadow>
+                                            </value>
+                                            <value name="value">
+                                              <shadow type="logic_null"/>
+                                              <block type="variables_get" id="M30M^ylqg=LNn8:gZP/N">
+                                                <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field>
+                                              </block>
+                                            </value>
+                                            <value name="qos">
+                                              <shadow type="math_number" id="SsA_tZ`x^1+}(_zKjKRu">
+                                                <field name="NUM">2</field>
+                                              </shadow>
+                                            </value>
+                                            <value name="retain">
+                                              <shadow type="logic_boolean" id="!*}`Y.znZ+z.oXK--9c-">
+                                                <field name="BOOL">FALSE</field>
+                                              </shadow>
+                                            </value>
+                                          </block>
+                                        </next>
+                                      </block>
+                                    </next>
+                                  </block>
+                                </next>
+                              </block>
+                            </next>
+                          </block>
+                        </next>
                       </block>
                     </next>
                   </block>
@@ -1329,7 +1955,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="5059">
+  <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="6063">
     <field name="NAME">initMQTTLocal</field>
     <statement name="STACK">
       <block type="variables_set" id="_C*fQdBXqrGb1uUWi?_1">
@@ -1425,7 +2051,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="5634">
+  <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="6638">
     <field name="NAME">thread_MQTTLocal</field>
     <statement name="STACK">
       <block type="util_python" id="IiRVsU4_~OPjE]@(VC;/" inline="true">
@@ -1441,7 +2067,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="5894">
+  <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="6898">
     <mutation>
       <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/>
       <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/>
@@ -1654,7 +2280,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="_OzPkP~3{!(`00$xIV+e" x="0" y="6684">
+  <block type="procedures_defnoreturn" id="_OzPkP~3{!(`00$xIV+e" x="0" y="7688">
     <mutation>
       <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/>
       <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/>
@@ -1670,7 +2296,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="W9;^Y=ye_P7SI[QLip%+" x="0" y="6904">
+  <block type="procedures_defnoreturn" id="W9;^Y=ye_P7SI[QLip%+" x="0" y="7908">
     <mutation>
       <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/>
       <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/>
@@ -1686,7 +2312,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="}B,U]C!V!/l^kl:ZS,ly" x="0" y="7103">
+  <block type="procedures_defnoreturn" id="}B,U]C!V!/l^kl:ZS,ly" x="0" y="8107">
     <mutation>
       <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/>
       <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/>
@@ -1704,7 +2330,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="7330">
+  <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="8334">
     <mutation>
       <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="`n4M@;+Y^Ab44Gi.YYy-"/>
       <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid="]gLOm[vhCT0;N+Cp[1?5"/>
diff --git a/lib/NodeRED.py b/lib/NodeRED.py
index 32a7e36ecd110dd6330d66039617527f440b5372..8106b12145940a7f53bcefc4398ee9639b8d8d63 100644
--- a/lib/NodeRED.py
+++ b/lib/NodeRED.py
@@ -1,12 +1,16 @@
 import json
 import logging
+import math
 import paho.mqtt.client as mqtt
 
 from datetime import datetime
 from fischertechnik.mqtt.MqttClient import MqttClient
+from lib.ColorCalib import *
 from lib.display import *
+from lib.DPS import *
 from lib.HBW_AxesNRef import *
 from lib.HBW_NodeRED import *
+from lib.SLD import *
 from lib.SLD_NodeRED import *
 from lib.SSC_Lights import *
 from lib.SSC_NodeRED import *
@@ -30,7 +34,14 @@ payload = None
 gtyp_Setup_x_Color_Sensor_Calibration = None
 state_positioning = None
 gtyp_Setup_i_Color_Sensor_Selection = None
+gtyp_Setup_w_Actual_ColorValue = None
+gtyp_Setup_w_Threshold_White_Red = None
+gtyp_Setup_w_Threshold_Red_Blue = None
+gtyp_SSC_w_Threshold_Red_Blue = None
 gtyp_Setup_di_Pos_Rotate = None
+gtyp_SLD_w_Threshold_Red_Blue = None
+gtyp_SSC_w_Threshold_White_Red = None
+gtyp_SLD_w_Threshold_White_Red = None
 gtyp_Setup_di_Pos_Vertical = None
 ts = None
 controller_name = None
@@ -38,7 +49,7 @@ gtyp_Setup_di_Pos_Horizontal = None
 
 
 def processReceivedMessage(topic, m_decode):
-    global client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     logging.log(logging.TRACE, '%s %s', topic, m_decode)
     if topic == 'gtyp_Setup/x_Set_Pos_Activ':
         logging.debug('activate')
@@ -121,12 +132,23 @@ def processReceivedMessage(topic, m_decode):
         logging.debug('offset')
     elif topic == 'gtyp_Setup/x_Set_Calib_Value_Color_Blue':
         logging.debug('blue')
+        set_calibvalue_blue(gtyp_Setup_w_Actual_ColorValue)
+        client.publish(topic='gtyp_Setup/w_Calib_ColorValue_Blue', payload=(get_calibvalue_list())[2], qos=2, retain=False)
     elif topic == 'gtyp_Setup/x_Set_Calib_Value_Color_Red':
         logging.debug('red')
+        set_calibvalue_red(gtyp_Setup_w_Actual_ColorValue)
+        client.publish(topic='gtyp_Setup/w_Calib_ColorValue_Red', payload=(get_calibvalue_list())[1], qos=2, retain=False)
     elif topic == 'gtyp_Setup/x_Set_Calib_Value_Color_White':
         logging.debug('white')
+        set_calibvalue_white(gtyp_Setup_w_Actual_ColorValue)
+        client.publish(topic='gtyp_Setup/w_Calib_ColorValue_White', payload=(get_calibvalue_list())[0], qos=2, retain=False)
     elif topic == 'gtyp_Setup/x_Calculate_Value_Color':
         logging.debug('calculate')
+        calculate_thresh()
+        gtyp_Setup_w_Threshold_White_Red = (get_thresh_list())[0]
+        gtyp_Setup_w_Threshold_Red_Blue = (get_thresh_list())[1]
+        client.publish(topic='gtyp_Setup/w_Threshold_White_Red', payload=gtyp_Setup_w_Threshold_White_Red, qos=2, retain=False)
+        client.publish(topic='gtyp_Setup/w_Threshold_Red_Blue', payload=gtyp_Setup_w_Threshold_Red_Blue, qos=2, retain=False)
     elif topic == 'gtyp_Setup/x_Color_Sensor_Calibration':
         logging.debug('calibrate color sensor')
         gtyp_Setup_x_Color_Sensor_Calibration = m_decode
@@ -136,15 +158,32 @@ def processReceivedMessage(topic, m_decode):
         else:
             set_lights_mode(0)
             display.set_attr("txt_status_indicator.active", str(False).lower())
+            gtyp_Setup_w_Actual_ColorValue = 0
     elif topic == 'gtyp_Setup/i_Color_Sensor_Selection':
         logging.debug('sensor selection')
         gtyp_Setup_i_Color_Sensor_Selection = int(m_decode, 10)
         if gtyp_Setup_i_Color_Sensor_Selection == 1:
             logging.debug('1')
+            gtyp_Setup_w_Actual_ColorValue = round(readColorValue())
+            gtyp_SLD_w_Threshold_Red_Blue = (get_calib_data_SLD())[0]
+            gtyp_SLD_w_Threshold_White_Red = (get_calib_data_SLD())[1]
         elif gtyp_Setup_i_Color_Sensor_Selection == 2:
             logging.debug('2')
+            gtyp_Setup_w_Actual_ColorValue = readDPSColorValue()
+            gtyp_SSC_w_Threshold_Red_Blue = (get_calib_data_DPS())[0]
+            gtyp_SSC_w_Threshold_White_Red = (get_calib_data_DPS())[1]
         else:
             logging.debug('none')
+            gtyp_SSC_w_Threshold_Red_Blue = 0
+            gtyp_SSC_w_Threshold_White_Red = 0
+            gtyp_SLD_w_Threshold_Red_Blue = 0
+            gtyp_SLD_w_Threshold_White_Red = 0
+            gtyp_Setup_w_Actual_ColorValue = 0
+        client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False)
+        client.publish(topic='gtyp_SLD/w_Threshold_White_Red', payload=gtyp_SLD_w_Threshold_White_Red, qos=2, retain=False)
+        client.publish(topic='gtyp_SLD/w_Threshold_Red_Blue', payload=gtyp_SLD_w_Threshold_Red_Blue, qos=2, retain=False)
+        client.publish(topic='gtyp_SSC/w_Threshold_White_Red', payload=gtyp_SSC_w_Threshold_White_Red, qos=2, retain=False)
+        client.publish(topic='gtyp_SSC/w_Threshold_Red_Blue', payload=gtyp_SSC_w_Threshold_Red_Blue, qos=2, retain=False)
     elif topic == 'gtyp_Setup/x_Counter_Value_Calibration':
         logging.debug('calibrate push out')
     elif topic == 'gtyp_Setup/x_Set_CounterValues':
@@ -162,7 +201,7 @@ def processReceivedMessage(topic, m_decode):
 
 
 def initMQTTLocal():
-    global topic, m_decode, client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     gtyp_Setup_x_Set_Pos_Activ = 0
     gtyp_Setup_i_Pos_Selection = 0
     gtyp_Setup_x_Color_Sensor_Calibration = 0
@@ -183,7 +222,7 @@ def initMQTTLocal():
 
 
 def thread_MQTTLocal():
-    global topic, m_decode, client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, client, userdata, flags, rc, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     logging.debug('-')
     #client.loop_forever()
     client.loop_start()
@@ -192,7 +231,7 @@ def thread_MQTTLocal():
 
 
 def on_connect(client, userdata, flags, rc):
-    global topic, m_decode, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     print("Connection returned result: "+mqtt.connack_string(rc))
     client.subscribe("#")
     #client.subscribe("$SYS/#")
@@ -209,23 +248,23 @@ def on_connect(client, userdata, flags, rc):
 
 
 def on_disconnect(client, userdata, rc):
-    global topic, m_decode, flags, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, flags, mid, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     if rc != 0:
       print("Unexpected disconnection.")
 
 
 def on_publish(client, userdata, mid):
-    global topic, m_decode, flags, rc, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, flags, rc, granted_qos, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     #print("on_publish")
 
 
 def on_subscribe(client, userdata, mid, granted_qos):
-    global topic, m_decode, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     print("on_subscribe")
 
 
 def on_message(client, userdata, msg):
-    global topic, m_decode, flags, rc, mid, granted_qos, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_di_Pos_Rotate, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
+    global topic, m_decode, flags, rc, mid, granted_qos, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal
     print("Received message '" + str(msg.payload) + "' on topic '"
             + msg.topic + "' with QoS " + str(msg.qos))
 
diff --git a/lib/SLD.blockly b/lib/SLD.blockly
index 985b54531025dd6a7d6ef2de6afd52c769313382..ef0e83d0eab1f7bb13c54557d4fdfe9eb92254da 100644
--- a/lib/SLD.blockly
+++ b/lib/SLD.blockly
@@ -4,17 +4,16 @@
     <variable id="x?rbx}Z!7+Jx9E.L=:pX">_code</variable>
     <variable id="Hq*BSR/(QEo9c0kQRW{y">_active</variable>
     <variable id="1X|m)*QO^oo}EfHf=nBO">speed</variable>
-    <variable id="2hXKDa]i2lK78Fcn!kS7">v</variable>
     <variable id="78bW9521)(I[oMydfNIz">state_code</variable>
     <variable id="[V))lfBm^j7t@3LJVWGf">state_active</variable>
-    <variable id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</variable>
-    <variable id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</variable>
     <variable id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</variable>
-    <variable id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</variable>
-    <variable id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</variable>
     <variable id="?]F?rtn:F#wq@5Ag|9yE">thresh_white_red_defaults</variable>
     <variable id="Krv1?O$_~Yha=/]3-u{i">thresh_red_blue_defaults</variable>
+    <variable id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</variable>
+    <variable id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</variable>
+    <variable id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</variable>
     <variable id="g%%DHmT#UX~.YdQn3gcf">_ts_state</variable>
+    <variable id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</variable>
     <variable id="caAu/l+mpfP^b1#tA{Kr">detectedColorValue</variable>
     <variable id="?Hi+81vv*K@yZim!8fD_">lastColorValue</variable>
     <variable id="_?QtuoxDM2ZJ#rQLHhaQ">counter</variable>
@@ -23,196 +22,7 @@
   <block type="util_python_imports" id=".e$$DS-W;QA]vq3]8xZ(" x="0" y="0">
     <field name="value">import logging</field>
   </block>
-  <block type="procedures_defnoreturn" id="CpW/ole-H2rC#biYY(;s" x="0" y="103">
-    <mutation>
-      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid=",],|#/r)~Xl=JL*8taHJ"/>
-    </mutation>
-    <field name="NAME">set_thresh_white_red</field>
-    <field name=",],|#/r)~Xl=JL*8taHJ">v</field>
-    <statement name="STACK">
-      <block type="variables_set" id="3*3|dp7u~ki(*nK_4Ekt">
-        <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
-        <value name="VALUE">
-          <block type="variables_get" id="/o6UTd6e2cy=Pj`s9)(c">
-            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
-          </block>
-        </value>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defnoreturn" id="h5y$(R^WIO%kMWuCgE+;" x="0" y="243">
-    <mutation>
-      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="Nz7/7d0Ek!?Vdf4NY1ae"/>
-    </mutation>
-    <field name="NAME">set_thresh_red_blue</field>
-    <field name="Nz7/7d0Ek!?Vdf4NY1ae">v</field>
-    <statement name="STACK">
-      <block type="variables_set" id="eNRG|p(-%_Yz!$K``W6e">
-        <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
-        <value name="VALUE">
-          <block type="variables_get" id="2|LmmIczudHT]_cFHQ(?">
-            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
-          </block>
-        </value>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defreturn" id="qn64~^UH=QV4|-w^OiX3" x="0" y="383">
-    <field name="NAME">get_thresh_list</field>
-    <value name="RETURN">
-      <block type="lists_create_with" id="?W6`HZcED/e(AP1BFbYr">
-        <mutation items="2"/>
-        <value name="ADD0">
-          <block type="variables_get" id="m1@Y1bkb,1*Dg+eexmKl">
-            <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
-          </block>
-        </value>
-        <value name="ADD1">
-          <block type="variables_get" id="a^.?2Q=ibO,1}0)/Gzic">
-            <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
-          </block>
-        </value>
-      </block>
-    </value>
-  </block>
-  <block type="procedures_defnoreturn" id="]HGe}R8RwUwfQdy0ms1)" x="0" y="533">
-    <field name="NAME">calculate_thresh</field>
-    <statement name="STACK">
-      <block type="variables_set" id="N:HH93LfZOGlsAZG*0jY">
-        <field name="VAR" id="P?9)xi9bG(6)T87+%iT!">thresh_white_red</field>
-        <value name="VALUE">
-          <block type="math_arithmetic" id="[kHN2Ju34-JM]=ZC}~f?">
-            <field name="OP">DIVIDE</field>
-            <value name="A">
-              <block type="math_arithmetic" id="Fr%[L18*%c*+$xkRRmm`">
-                <field name="OP">ADD</field>
-                <value name="A">
-                  <block type="variables_get" id="RSPH{qq0p*_4E(i!EK*8">
-                    <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
-                  </block>
-                </value>
-                <value name="B">
-                  <block type="variables_get" id="5*`ipxd4{J+n1q|w{zP|">
-                    <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
-                  </block>
-                </value>
-              </block>
-            </value>
-            <value name="B">
-              <block type="math_number" id="LtL_9k`{^Y-{qpG{QxgS">
-                <field name="NUM">2</field>
-              </block>
-            </value>
-          </block>
-        </value>
-        <next>
-          <block type="variables_set" id="3S~xH!-(5jp{N@[Pb]w;">
-            <field name="VAR" id="c5f:;cPsd?218L=sb[nF">thresh_red_blue</field>
-            <value name="VALUE">
-              <block type="math_arithmetic" id="w,QV?:Z:8I@CqD-ihD0C">
-                <field name="OP">DIVIDE</field>
-                <value name="A">
-                  <block type="math_arithmetic" id="wmEObo)Jdr;sB0A=s3aF">
-                    <field name="OP">ADD</field>
-                    <value name="A">
-                      <block type="variables_get" id="]vb#C}h4E[V$hzr5g55@">
-                        <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
-                      </block>
-                    </value>
-                    <value name="B">
-                      <block type="variables_get" id="IbH+K4}=A;gbp*8R,31%">
-                        <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
-                      </block>
-                    </value>
-                  </block>
-                </value>
-                <value name="B">
-                  <block type="math_number" id="h(o(_rZpB6ZmzlHuM9V}">
-                    <field name="NUM">2</field>
-                  </block>
-                </value>
-              </block>
-            </value>
-          </block>
-        </next>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defreturn" id="9Cj-Yafy$tg0`VH?3)S=" x="0" y="713">
-    <field name="NAME">get_calibvalue_list</field>
-    <value name="RETURN">
-      <block type="lists_create_with" id="Wj)6C/61+mbvY6}p$eoh">
-        <mutation items="3"/>
-        <value name="ADD0">
-          <block type="variables_get" id="5v3ziq5pvqDqT/9ZVwP,">
-            <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
-          </block>
-        </value>
-        <value name="ADD1">
-          <block type="variables_get" id="jWM[pB(F5IbtNLP-Bpb.">
-            <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
-          </block>
-        </value>
-        <value name="ADD2">
-          <block type="variables_get" id="Z@i#@^B6DW,*;PXxhc$4">
-            <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
-          </block>
-        </value>
-      </block>
-    </value>
-  </block>
-  <block type="procedures_defnoreturn" id="~J*0~mN(wH1HdQ6+g*8O" x="0" y="892">
-    <mutation>
-      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="I@B?}jt30*H/Nrzr)p2."/>
-    </mutation>
-    <field name="NAME">set_calibvalue_white</field>
-    <field name="I@B?}jt30*H/Nrzr)p2.">v</field>
-    <statement name="STACK">
-      <block type="variables_set" id="u,NtKTmx-[!KhZUdvkHW">
-        <field name="VAR" id="?hGLg[3H[9:g]?:4%%_%">calibvalue_white</field>
-        <value name="VALUE">
-          <block type="variables_get" id="2c{|eTtuT+eA#t@SrFza">
-            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
-          </block>
-        </value>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defnoreturn" id="uiAN]3!dL*HgM2PpP/Mr" x="0" y="1032">
-    <mutation>
-      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="`,@l)KD{{wbrC!|u;.cC"/>
-    </mutation>
-    <field name="NAME">set_calibvalue_red</field>
-    <field name="`,@l)KD{{wbrC!|u;.cC">v</field>
-    <statement name="STACK">
-      <block type="variables_set" id="rAVx5ZwsP~^Ist#lCB4Q">
-        <field name="VAR" id="yo`fPT*$(K2EHr+p;E@^">calibvalue_red</field>
-        <value name="VALUE">
-          <block type="variables_get" id="h~F1rD.B2[TwE|gC@qJh">
-            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
-          </block>
-        </value>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defnoreturn" id="9]2A$:IB|S6O$D~zhA=2" x="0" y="1172">
-    <mutation>
-      <arg name="v" varid="2hXKDa]i2lK78Fcn!kS7" argid="|#3L}sF}`~w2aK|mn7._"/>
-    </mutation>
-    <field name="NAME">set_calibvalue_blue</field>
-    <field name="|#3L}sF}`~w2aK|mn7._">v</field>
-    <statement name="STACK">
-      <block type="variables_set" id="QtVj+{4OkTrFB5EM^Ye@">
-        <field name="VAR" id="u~VUTh^5;XCqV.t^iE,B">calibvalue_blue</field>
-        <value name="VALUE">
-          <block type="variables_get" id="|0z?+.gMKUwLyinAgUEX">
-            <field name="VAR" id="2hXKDa]i2lK78Fcn!kS7">v</field>
-          </block>
-        </value>
-      </block>
-    </statement>
-  </block>
-  <block type="procedures_defnoreturn" id="]$}!d~iPi$faCfYn-,02" x="0" y="1312">
+  <block type="procedures_defnoreturn" id="]$}!d~iPi$faCfYn-,02" x="0" y="101">
     <field name="NAME">thread_SLD</field>
     <statement name="STACK">
       <block type="util_python" id="or=tulIX]{S?#ofKV+]h" inline="true">
@@ -776,7 +586,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defreturn" id="x=/1p3KO=Q%QK7t2K5l%" x="0" y="3295">
+  <block type="procedures_defreturn" id="x=/1p3KO=Q%QK7t2K5l%" x="0" y="2030">
     <field name="NAME">get_calib_data_SLD_defaults</field>
     <statement name="STACK">
       <block type="util_python" id="cO!#.ICg79WkS?A?cG[j" inline="true">
@@ -799,7 +609,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="b|1;0mU=wNNO2Ry{f6,Z" x="0" y="3460">
+  <block type="procedures_defreturn" id="b|1;0mU=wNNO2Ry{f6,Z" x="0" y="2191">
     <field name="NAME">get_calib_data_SLD</field>
     <statement name="STACK">
       <block type="util_python" id="t;Zg(`vb3R)aQZ])LhpC" inline="true">
@@ -822,7 +632,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defnoreturn" id="3Qf0~|~$oG8z5tP{6Km;" x="0" y="3625">
+  <block type="procedures_defnoreturn" id="3Qf0~|~$oG8z5tP{6Km;" x="0" y="2352">
     <mutation>
       <arg name="_data" varid="$E/GDp,,dwQrGbs7N*=C" argid="^}Z*XZLpIfstV5L7ggN|"/>
     </mutation>
@@ -878,7 +688,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="gsD|}/@_.f.D_8KfM;**" x="0" y="3849">
+  <block type="procedures_defnoreturn" id="gsD|}/@_.f.D_8KfM;**" x="0" y="2571">
     <mutation>
       <arg name="_code" varid="x?rbx}Z!7+Jx9E.L=:pX" argid=",ZCb|vi(m3g0A4u*(!{`"/>
       <arg name="_active" varid="Hq*BSR/(QEo9c0kQRW{y" argid="mqa@Al(.5xeP*B]Jl`8%"/>
@@ -961,7 +771,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defreturn" id="eO[xQ[akMe*EVjm,{7m0" x="0" y="4203">
+  <block type="procedures_defreturn" id="eO[xQ[akMe*EVjm,{7m0" x="0" y="2916">
     <field name="NAME">get_state_code_SLD</field>
     <statement name="STACK">
       <block type="util_python" id="(HOmJd*Bw@nwPNCHY0mu" inline="true">
@@ -974,7 +784,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="wpN6M:c*2cKgK+MM+G.W" x="0" y="4339">
+  <block type="procedures_defreturn" id="wpN6M:c*2cKgK+MM+G.W" x="0" y="3049">
     <field name="NAME">get_state_active_SLD</field>
     <statement name="STACK">
       <block type="util_python" id="Ht%%JB`?HUum}h9K*t-9" inline="true">
@@ -987,7 +797,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defnoreturn" id="%z2U,T)U0wd2S}!Lot[s" x="0" y="4475">
+  <block type="procedures_defnoreturn" id="%z2U,T)U0wd2S}!Lot[s" x="0" y="3182">
     <mutation>
       <arg name="speed" varid="1X|m)*QO^oo}EfHf=nBO" argid="pePpK@*+w{Ry]Ltz(Z95"/>
     </mutation>
@@ -1013,7 +823,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="IKFw+yZgK[}QgIvIQk]A" x="0" y="4650">
+  <block type="procedures_defnoreturn" id="IKFw+yZgK[}QgIvIQk]A" x="0" y="3353">
     <field name="NAME">ejectWhite</field>
     <statement name="STACK">
       <block type="util_python" id="L9].u`N0?,H+tU)=o?Me" inline="true">
@@ -1089,7 +899,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="M^8-tj!Sv{KHcQSAS;$K" x="0" y="5027">
+  <block type="procedures_defnoreturn" id="M^8-tj!Sv{KHcQSAS;$K" x="0" y="3720">
     <field name="NAME">ejectRed</field>
     <statement name="STACK">
       <block type="util_python" id="?:UCrMJUl%q(jYcN8(IE" inline="true">
@@ -1165,7 +975,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defnoreturn" id="YLSy9_KOy{GM#LBmqJ8x" x="0" y="5404">
+  <block type="procedures_defnoreturn" id="YLSy9_KOy{GM#LBmqJ8x" x="0" y="4087">
     <field name="NAME">ejectBlue</field>
     <statement name="STACK">
       <block type="util_python" id="n-s%L0Ie7qkf@WU-[H8o" inline="true">
@@ -1241,7 +1051,7 @@
       </block>
     </statement>
   </block>
-  <block type="procedures_defreturn" id="0.,m:~DVx{zBe-|XxpG-" x="0" y="5781">
+  <block type="procedures_defreturn" id="0.,m:~DVx{zBe-|XxpG-" x="0" y="4454">
     <field name="NAME">isColorSensorTriggered</field>
     <statement name="STACK">
       <block type="util_python" id="23n|f!bBfO#m?@_HlHB}" inline="true">
@@ -1255,7 +1065,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="}*yI=aY}$^7875;e4Wo_" x="0" y="5917">
+  <block type="procedures_defreturn" id="}*yI=aY}$^7875;e4Wo_" x="0" y="4587">
     <field name="NAME">isEjectionTriggered</field>
     <statement name="STACK">
       <block type="util_python" id="wrT1c1;%@kF-Riy28O;." inline="true">
@@ -1269,7 +1079,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="Fys9OK!K-FNH-W0o}@h," x="0" y="6053">
+  <block type="procedures_defreturn" id="Fys9OK!K-FNH-W0o}@h," x="0" y="4720">
     <field name="NAME">isWhite</field>
     <statement name="STACK">
       <block type="util_python" id="h?(Tr@S1VYchJ5e6())[" inline="true">
@@ -1283,7 +1093,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="iE@eN47vK?la`*X4EQ-8" x="0" y="6189">
+  <block type="procedures_defreturn" id="iE@eN47vK?la`*X4EQ-8" x="0" y="4853">
     <field name="NAME">isRed</field>
     <statement name="STACK">
       <block type="util_python" id="fN{]~9g]|*Kx,bpmy_i$" inline="true">
@@ -1297,7 +1107,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="w|KTmb#01-L]2ZG4mz)b" x="0" y="6325">
+  <block type="procedures_defreturn" id="w|KTmb#01-L]2ZG4mz)b" x="0" y="4986">
     <field name="NAME">isBlue</field>
     <statement name="STACK">
       <block type="util_python" id="U(Y(8WN=vCJzgw~oLdbs" inline="true">
@@ -1311,7 +1121,7 @@
       </block>
     </value>
   </block>
-  <block type="procedures_defreturn" id="$]uSxm9]*Qu3iZl~w~MW" x="0" y="6461">
+  <block type="procedures_defreturn" id="$]uSxm9]*Qu3iZl~w~MW" x="0" y="5119">
     <field name="NAME">readColorValue</field>
     <statement name="STACK">
       <block type="util_python" id="JSm|]EZ0cs6:5)g-C23(" inline="true">
diff --git a/lib/SLD.py b/lib/SLD.py
index 7825af8facd124248fc8941c2c327438b4982b62..262e9207633cf4487890937a64c49367dc1a496a 100644
--- a/lib/SLD.py
+++ b/lib/SLD.py
@@ -6,70 +6,28 @@ from lib.controller import *
 from numbers import Number
 
 
-v = None
 _data = None
 _code = None
 _active = None
 speed = None
-thresh_white_red = None
-thresh_red_blue = None
-calibvalue_white = None
-calibvalue_red = None
-calibvalue_blue = None
 state_code = None
 state_active = None
+calibvalue_white = None
 thresh_white_red_defaults = None
 thresh_red_blue_defaults = None
+thresh_white_red = None
+thresh_red_blue = None
+calibvalue_red = None
 _ts_state = None
+calibvalue_blue = None
 detectedColorValue = None
 lastColorValue = None
 counter = None
 lastStateCounterSwitch = None
 
 
-def set_thresh_white_red(v):
-    global _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    thresh_white_red = v
-
-
-def set_thresh_red_blue(v):
-    global _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    thresh_red_blue = v
-
-
-def get_thresh_list():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    return [thresh_white_red, thresh_red_blue]
-
-
-def calculate_thresh():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    thresh_white_red = (calibvalue_white + calibvalue_red) / 2
-    thresh_red_blue = (calibvalue_red + calibvalue_blue) / 2
-
-
-def get_calibvalue_list():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    return [calibvalue_white, calibvalue_red, calibvalue_blue]
-
-
-def set_calibvalue_white(v):
-    global _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    calibvalue_white = v
-
-
-def set_calibvalue_red(v):
-    global _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    calibvalue_red = v
-
-
-def set_calibvalue_blue(v):
-    global _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
-    calibvalue_blue = v
-
-
 def thread_SLD():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     calibvalue_white = 0
     calibvalue_red = 0
@@ -126,26 +84,26 @@ def thread_SLD():
 
 
 def get_calib_data_SLD_defaults():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     return [thresh_white_red_defaults, thresh_red_blue_defaults]
 
 
 def get_calib_data_SLD():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     return [thresh_white_red, thresh_red_blue]
 
 
 def set_calib_data_SLD(_data):
-    global v, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, _data)
     thresh_white_red = _data[0]
     thresh_red_blue = _data[1]
 
 
 def _set_state_SLD(_code, _active):
-    global v, _data, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     if state_code != _code or state_active != _active:
         _ts_state = 0
@@ -154,26 +112,26 @@ def _set_state_SLD(_code, _active):
 
 
 def get_state_code_SLD():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return state_code
 
 
 def get_state_active_SLD():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return state_active
 
 
 def setConvBeltSpeedSLD(speed):
-    global v, _data, _code, _active, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, 'speed: %d', speed)
     TXT_SLD_E5_M1_encodermotor.set_speed(int(speed), Motor.CW)
     TXT_SLD_E5_M1_encodermotor.start()
 
 
 def ejectWhite():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     TXT_SLD_E5_O5_magnetic_valve.on()
     time.sleep(0.5)
@@ -187,7 +145,7 @@ def ejectWhite():
 
 
 def ejectRed():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     TXT_SLD_E5_O6_magnetic_valve.on()
     time.sleep(0.5)
@@ -201,7 +159,7 @@ def ejectRed():
 
 
 def ejectBlue():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE, '-')
     TXT_SLD_E5_O7_magnetic_valve.on()
     time.sleep(0.5)
@@ -215,37 +173,37 @@ def ejectBlue():
 
 
 def isColorSensorTriggered():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I1_photo_transistor.is_dark()
 
 
 def isEjectionTriggered():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I3_photo_transistor.is_dark()
 
 
 def isWhite():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I6_photo_transistor.is_dark()
 
 
 def isRed():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I7_photo_transistor.is_dark()
 
 
 def isBlue():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I8_photo_transistor.is_dark()
 
 
 def readColorValue():
-    global v, _data, _code, _active, speed, thresh_white_red, thresh_red_blue, calibvalue_white, calibvalue_red, calibvalue_blue, state_code, state_active, thresh_white_red_defaults, thresh_red_blue_defaults, _ts_state, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
+    global _data, _code, _active, speed, state_code, state_active, calibvalue_white, thresh_white_red_defaults, thresh_red_blue_defaults, thresh_white_red, thresh_red_blue, calibvalue_red, _ts_state, calibvalue_blue, detectedColorValue, lastColorValue, counter, lastStateCounterSwitch
     logging.log(logging.TRACE0, '-')
     return TXT_SLD_E5_I2_color_sensor.get_voltage()
 
diff --git a/lib/Sound.py b/lib/Sound.py
index 87798bfbcec4697acf180541648ffe572dd4f6dd..24b9b0669ab9a836b55db650cd15917859794cc8 100644
--- a/lib/Sound.py
+++ b/lib/Sound.py
@@ -3,7 +3,6 @@ import threading
 import time
 
 from lib.controller import *
-from lib.Sound import *
 
 
 def beep():