- Home
- Deutsch
- Skripten / Logik
- Blockly
- Leuchtmittel mit 3 festen Stufen (100, 50, 25%) steuern
Leuchtmittel mit 3 festen Stufen (100, 50, 25%) steuern
This topic has been deleted. Only users with topic management privileges can see it.
-
Habe hier ein paar LEDs, die man über "kein Strom, Strom" in der Helligkeit regulieren kann.
Dabei starten sie immer mit voller Helligkeit, wenn sie mal eine Weile ohne Strom waren, gehen dann auf 50, 25 und schließlich wieder 100%.Dafür habe ich mir nun dieses kleine Blockly (Code im "Spoiler") angelegt (Basis ist ein Smart Home Gerät mit einem Datenpunkt der die Werte 0-3 aufnimmt):
<xml xmlns="http://www.w3.org/1999/xhtml"> <variables> <variable type="" id="]woI7PowI8]B4exB,s8C">ist</variable> <variable type="" id="IIaFUD}V^jpg){~KJMd6">soll</variable> <variable type="" id="6J;-Li!qUM!svhzjaAd:">schritte</variable> <variable type="undefined" id="Intervall">Intervall</variable> </variables> <block type="on" id="`88Gg@6F@YX2q;q65t])" x="-363" y="288"> <field name="OID">0_userdata.0.ecklampe</field> <field name="CONDITION">ne</field> <field name="ACK_CONDITION"></field> <statement name="STATEMENT"> <block type="variables_set" id="{PKtg!1L-;jS1y1S5Q0g"> <field name="VAR" id="]woI7PowI8]B4exB,s8C" variabletype="">ist</field> <value name="VALUE"> <block type="on_source" id="}k)Ebg4{4z%la(uS8L}p"> <field name="ATTR">oldState.val</field> </block> </value> <next> <block type="variables_set" id="$_l8ScsYjd;%#]EHQ;xW"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> <value name="VALUE"> <block type="on_source" id="Y95x`U;$9C6eA(Cx=-mi"> <field name="ATTR">state.val</field> </block> </value> <next> <block type="controls_if" id="s~~wqBJ-mdMaMztUD8f4"> <mutation else="1"></mutation> <value name="IF0"> <block type="logic_compare" id="d6q^mvpu!g@tCe/.JWg*"> <field name="OP">EQ</field> <value name="A"> <block type="variables_get" id="@XDWuU[^ia{esX|sSO8$"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> </block> </value> <value name="B"> <block type="math_number" id="aCf}{Mf5-E~sD.3aQy!k"> <field name="NUM">0</field> </block> </value> </block> </value> <statement name="DO0"> <block type="control" id="7uta;_0ls#r7a??(oXv?"> <mutation delay_input="false"></mutation> <field name="OID">broadlink2.0.RMPROPLUS-42-fb-44.L.ecklampe_aus</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="5dZS)dm*O!ktu;/fC9B/"> <field name="BOOL">TRUE</field> </block> </value> </block> </statement> <statement name="ELSE"> <block type="controls_if" id="zfnibv6sAebh27qW=(Ha"> <mutation elseif="1" else="1"></mutation> <value name="IF0"> <block type="logic_compare" id="}cFfC}?h)5M:YW;!S*bW"> <field name="OP">GT</field> <value name="A"> <block type="variables_get" id="ick{mQ$bzYD{jh._aB;q"> <field name="VAR" id="]woI7PowI8]B4exB,s8C" variabletype="">ist</field> </block> </value> <value name="B"> <block type="variables_get" id="Xydy?_ycv]s^YV$Z=~32"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> </block> </value> </block> </value> <statement name="DO0"> <block type="variables_set" id="Yx!q,~PgZy(L/dRa]!Zd"> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> <value name="VALUE"> <block type="math_arithmetic" id="nSn_heblgvL5z:B9q2M4"> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="zCw4#1S))zrmM{hy98o`"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="p;JUFIp-n`vBrbdMqqX3"> <field name="VAR" id="]woI7PowI8]B4exB,s8C" variabletype="">ist</field> </block> </value> <value name="B"> <shadow type="math_number" id="Fr}iUu5g;3ewh--0*;Aa"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="?)VG4f=#~)UiHm*C9fXi"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> </block> </value> </block> </value> </block> </statement> <value name="IF1"> <block type="logic_compare" id="AlzVLB9e,)_g`JH+BYFv"> <field name="OP">EQ</field> <value name="A"> <block type="variables_get" id="2(?}qlL*OxPKhIA=;e7q"> <field name="VAR" id="]woI7PowI8]B4exB,s8C" variabletype="">ist</field> </block> </value> <value name="B"> <block type="math_number" id="1Y2D060c0Y+@i3[i%Y2j"> <field name="NUM">0</field> </block> </value> </block> </value> <statement name="DO1"> <block type="variables_set" id="e%p}8m?ee{9{ux[e1SV8"> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> <value name="VALUE"> <block type="math_arithmetic" id="Ox9:VokpBdSu4,;H[-b9"> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="u8T,^^Qe]~MiveCM{Ivx"> <field name="NUM">4</field> </shadow> </value> <value name="B"> <shadow type="math_number" id="IVxm:E;S`[??)rT`ETvR"> <field name="NUM">0</field> </shadow> <block type="variables_get" id=".^UX-BD]![Wf0_t,tosd"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> </block> </value> </block> </value> </block> </statement> <statement name="ELSE"> <block type="variables_set" id="WnJF!L*RQ2Mp9[6lLsx0"> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> <value name="VALUE"> <block type="math_arithmetic" id="7U`S%3iokb2ZwLk5|)18"> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="DtLkp8YaB[R[Kk02twfj"> <field name="NUM">3</field> </shadow> </value> <value name="B"> <shadow type="math_number" id="pPU^5Bfl`(L@Z;,t^Qtk"> <field name="NUM">0</field> </shadow> <block type="math_arithmetic" id=":l#Qsu?Bz+S^C}~VbMiG"> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="zCw4#1S))zrmM{hy98o`"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="Wys_V@V{XU%DRp5_~OU6"> <field name="VAR" id="IIaFUD}V^jpg){~KJMd6" variabletype="">soll</field> </block> </value> <value name="B"> <shadow type="math_number" id="Fr}iUu5g;3ewh--0*;Aa"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="-^jLzu90wWD2s81t%z!5"> <field name="VAR" id="]woI7PowI8]B4exB,s8C" variabletype="">ist</field> </block> </value> </block> </value> </block> </value> </block> </statement> <next> <block type="timeouts_setinterval" id="[tR99_Nk|F%q*h=M?%sQ"> <field name="NAME">Intervall</field> <field name="INTERVAL">400</field> <field name="UNIT">ms</field> <statement name="STATEMENT"> <block type="control" id="eUHoJPW^k:U.:J3wtv+T"> <mutation delay_input="false"></mutation> <field name="OID">broadlink2.0.RMPROPLUS-42-fb-44.L.ecklampe_aus</field> <field name="WITH_DELAY">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="n(~p0K#[W@+Iv4g?]*@F"> <field name="BOOL">TRUE</field> </block> </value> <next> <block type="control" id=":8*TGG@q=(5qJc{!tpXC"> <mutation delay_input="true"></mutation> <field name="OID">broadlink2.0.RMPROPLUS-42-fb-44.L.ecklampe_an</field> <field name="WITH_DELAY">TRUE</field> <field name="DELAY_MS">200</field> <field name="UNIT">ms</field> <field name="CLEAR_RUNNING">FALSE</field> <value name="VALUE"> <block type="logic_boolean" id="n4)sNRN2[FG4_g{5k7iD"> <field name="BOOL">TRUE</field> </block> </value> <next> <block type="variables_set" id="aQQPY0P2o+DzfB3cd?_("> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> <value name="VALUE"> <block type="math_arithmetic" id="o;rT|3t,X)D.0r6tTAOA"> <field name="OP">MINUS</field> <value name="A"> <shadow type="math_number" id="#L%Cs9a3|+EE+h@WOoJY"> <field name="NUM">1</field> </shadow> <block type="variables_get" id="rGEeXW1QHvAej9hs/;N!"> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> </block> </value> <value name="B"> <shadow type="math_number" id="Q6V:k%eQ@DJkFK0M`UXH"> <field name="NUM">1</field> </shadow> </value> </block> </value> <next> <block type="controls_if" id="ZU]_T8biy}we)f9SXza}"> <value name="IF0"> <block type="logic_compare" id=")8rQ8|Nv^k7)vFG`P3^)"> <field name="OP">LTE</field> <value name="A"> <block type="variables_get" id="+hMp7kj6Q299G9IdeubR"> <field name="VAR" id="6J;-Li!qUM!svhzjaAd:" variabletype="">schritte</field> </block> </value> <value name="B"> <block type="math_number" id="M8S0upJR+Z(w[?*y|dmq"> <field name="NUM">0</field> </block> </value> </block> </value> <statement name="DO0"> <block type="timeouts_clearinterval" id="y%oYG3KF(mH-B*3*M;Uy"> <field name="NAME">Intervall</field> </block> </statement> </block> </next> </block> </next> </block> </next> </block> </statement> </block> </next> </block> </statement> </block> </next> </block> </next> </block> </statement> </block> </xml>
Funktioniert hier, soweit ich das sehen kann.
Evtl. kann es ja jemand brauchen.
Falls jemand einen eleganteren Algorithmus hat bin ich natürlich ganz Ohr. -
Bisschen umgebaut, weil es sonst durch "schlechtes Timing" zu undefinierten Variablen und damit zu Problemen (Stichwort: Endlosschleife) kommen konnte.