Site updated at 2016-04-14 16:44:25 UTC

This commit is contained in:
Travis CI 2016-04-14 16:44:25 +00:00
parent e1af4db93e
commit 754d956e42
16 changed files with 351 additions and 341 deletions

View file

@ -195,48 +195,50 @@
<h3><a class="title-link" name="example-sketch" href="#example-sketch"></a> Example sketch</h3>
<p>```c++<br />
/*<br />
* Documentation: http://www.mysensors.org<br />
* Support Forum: http://forum.mysensors.org<br />
*<br />
* http://www.mysensors.org/build/relay<br />
*/</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre><span class="comment">/*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/relay
*/</span>
<p>#include <mysensor.h>
#include <spi.h></spi.h></mysensor.h></p>
<span class="preprocessor">#include</span> <span class="include">&lt;MySensor.h&gt;</span>
<span class="preprocessor">#include</span> <span class="include">&lt;SPI.h&gt;</span>
<p>#define SN “Relay”<br />
#define SV “1.0”<br />
#define CHILD_ID 1<br />
#define RELAY_PIN 3</p>
<span class="preprocessor">#define</span> SN <span class="string"><span class="delimiter">&quot;</span><span class="content">Relay</span><span class="delimiter">&quot;</span></span>
<span class="preprocessor">#define</span> SV <span class="string"><span class="delimiter">&quot;</span><span class="content">1.0</span><span class="delimiter">&quot;</span></span>
<span class="preprocessor">#define</span> CHILD_ID <span class="integer">1</span>
<span class="preprocessor">#define</span> RELAY_PIN <span class="integer">3</span>
<p>MySensor gw;<br />
MyMessage msgRelay(CHILD_ID, V_STATUS);</p>
MySensor gw;
MyMessage msgRelay(CHILD_ID, V_STATUS);
<p>void setup()<br />
{<br />
gw.begin(incomingMessage);<br />
gw.sendSketchInfo(SN, SV);<br />
// Initialize the digital pin as an output.<br />
pinMode(RELAY_PIN, OUTPUT);<br />
gw.present(CHILD_ID, S_BINARY);<br />
gw.send(msgRelay.set(0));<br />
}</p>
<span class="directive">void</span> setup()
{
gw.begin(incomingMessage);
gw.sendSketchInfo(SN, SV);
<span class="comment">// Initialize the digital pin as an output.</span>
pinMode(RELAY_PIN, OUTPUT);
gw.present(CHILD_ID, S_BINARY);
gw.send(msgRelay.set(<span class="integer">0</span>));
}
<p>void loop()<br />
{<br />
gw.process();<br />
}</p>
<span class="directive">void</span> loop()
{
gw.process();
}
<p>void incomingMessage(const MyMessage &amp;message)<br />
{<br />
if (message.type == V_STATUS) {<br />
// Change relay state.<br />
digitalWrite(RELAY_PIN, message.getBool() ? 1 : 0);<br />
}<br />
}<br />
```</p>
<span class="directive">void</span> incomingMessage(<span class="directive">const</span> MyMessage &amp;message)
{
<span class="keyword">if</span> (message.type == V_STATUS) {
<span class="comment">// Change relay state.</span>
digitalWrite(RELAY_PIN, message.getBool() ? <span class="integer">1</span> : <span class="integer">0</span>);
}
}
</pre></div>
</div>
</div>