Site updated at 2016-04-14 15:50:18 UTC

This commit is contained in:
Travis CI 2016-04-14 15:50:18 +00:00
parent ca40d62a3d
commit e1af4db93e
17 changed files with 398 additions and 184 deletions

View file

@ -177,6 +177,53 @@
<p>For more information, visit the <a href="https://www.mysensors.org/download/serial_api_15">serial api</a> of MySensors.</p>
<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/binary<br />
*/</p>
<p>#include <mysensor.h>
#include <spi.h>
#include <bounce2.h></bounce2.h></spi.h></mysensor.h></p>
<p>#define SN “BinarySensor”<br />
#define SV “1.0”<br />
#define CHILD_ID 1<br />
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch.</p>
<p>MySensor gw;<br />
Bounce debouncer = Bounce();<br />
MyMessage msg(CHILD_ID, V_TRIPPED);</p>
<p>void setup()<br />
{<br />
gw.begin();<br />
gw.sendSketchInfo(SN, SV);<br />
// Setup the button.<br />
pinMode(BUTTON_PIN, INPUT_PULLUP);<br />
// After setting up the button, setup debouncer.<br />
debouncer.attach(BUTTON_PIN);<br />
debouncer.interval(5);<br />
gw.present(CHILD_ID, S_DOOR);<br />
gw.send(msg.set(0));<br />
}</p>
<p>void loop()<br />
{<br />
if (debouncer.update()) {<br />
// Get the update value.<br />
int value = debouncer.read();<br />
// Send in the new value.<br />
gw.send(msg.set(value == LOW ? 1 : 0));<br />
}<br />
}<br />
```</p>
</article>

View file

@ -159,6 +159,80 @@
<p>For more information, visit the <a href="https://www.mysensors.org/download/serial_api_15">serial api</a> of MySensors.</p>
<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/dimmer<br />
*/</p>
<p>#include <mysensor.h>
#include <spi.h></spi.h></mysensor.h></p>
<p>#define SN “DimmableRGBLED”<br />
#define SV “1.0”<br />
#define CHILD_ID 1<br />
#define LED_PIN 5</p>
<p>MySensor gw;</p>
<p>char rgb[7] = “ffffff”; // RGB value.<br />
int currentLevel = 0; // Current dimmer level.<br />
MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE);<br />
MyMessage lightMsg(CHILD_ID, V_STATUS);<br />
MyMessage rgbMsg(CHILD_ID, V_RGB);</p>
<p>void setup()<br />
{<br />
gw.begin(incomingMessage);<br />
gw.sendSketchInfo(SN, SV);<br />
gw.present(CHILD_ID, S_RGB_LIGHT);<br />
// Send initial values.<br />
gw.send(lightMsg.set(currentLevel &gt; 0 ? 1 : 0));<br />
gw.send(dimmerMsg.set(currentLevel));<br />
gw.send(rgbMsg.set(rgb));<br />
}</p>
<p>void loop()<br />
{<br />
gw.process();<br />
}</p>
<p>void incomingMessage(const MyMessage &amp;message) {<br />
if (message.type == V_RGB) {<br />
// Retrieve the RGB value from the incoming message.<br />
// RGB LED not implemented, just a dummy print.<br />
String hexstring = message.getString();<br />
hexstring.toCharArray(rgb, sizeof(rgb));<br />
Serial.print(“Changing color to “);<br />
Serial.println(rgb);<br />
gw.send(rgbMsg.set(rgb));<br />
}</p>
<p>if (message.type == V_STATUS || message.type == V_PERCENTAGE) {<br />
// Retrieve the light status or dimmer level from the incoming message.<br />
int requestedLevel = atoi(message.data);</p>
<pre><code>// Adjust incoming level if this is a V_LIGHT update [0 == off, 1 == on].
requestedLevel *= (message.type == V_STATUS ? 100 : 1);
// Clip incoming level to valid range of 0 to 100
requestedLevel = requestedLevel &gt; 100 ? 100 : requestedLevel;
requestedLevel = requestedLevel &lt; 0 ? 0 : requestedLevel;
// Change level value of LED pin.
analogWrite(LED_PIN, (int)(requestedLevel / 100. * 255));
currentLevel = requestedLevel;
// Update the gateway with the current V_STATUS and V_PERCENTAGE.
gw.send(lightMsg.set(currentLevel &gt; 0 ? 1 : 0));
gw.send(dimmerMsg.set(currentLevel));
} } ```
</code></pre>
</article>

View file

@ -132,7 +132,7 @@
<span class="key">debug</span>: <span class="string"><span class="content">true</span></span>
<span class="key">persistence</span>: <span class="string"><span class="content">true</span></span>
<span class="key">version</span>: <span class="string"><span class="content">'1.5'</span></span>
<span class="key">optimistic</span>: <span class="string"><span class="content">'true'</span></span>
<span class="key">optimistic</span>: <span class="string"><span class="content">false</span></span>
</pre></div>
</div>
</div>

View file

@ -247,6 +247,54 @@
<p>For more information, visit the <a href="https://www.mysensors.org/download/serial_api_15">serial api</a> of MySensors.</p>
<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/light<br />
*/</p>
<p>#include <spi.h>
#include <mysensor.h>
#include <bh1750.h>
#include <wire.h></wire.h></bh1750.h></mysensor.h></spi.h></p>
<p>#define SN “LightLuxSensor”<br />
#define SV “1.0”<br />
#define CHILD_ID 1<br />
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)</p>
<p>BH1750 lightSensor;<br />
MySensor gw;<br />
MyMessage msg(CHILD_ID, V_LEVEL);<br />
MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.<br />
uint16_t lastlux = 0;</p>
<p>void setup() <br />
{<br />
gw.begin();<br />
gw.sendSketchInfo(SN, SV);<br />
gw.present(CHILD_ID, S_LIGHT_LEVEL);<br />
lightSensor.begin();<br />
gw.send(msg.set(lastlux));<br />
gw.send(msgPrefix.set(“lux”)); // Set custom unit.<br />
}</p>
<p>void loop() <br />
{ <br />
uint16_t lux = lightSensor.readLightLevel(); // Get Lux value<br />
if (lux != lastlux) {<br />
gw.send(msg.set(lux));<br />
lastlux = lux;<br />
}</p>
<p>gw.sleep(SLEEP_TIME);<br />
}<br />
```</p>
</article>

View file

@ -193,6 +193,51 @@
<p>For more information, visit the <a href="https://www.mysensors.org/download/serial_api_15">serial api</a> of MySensors.</p>
<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>
<p>#include <mysensor.h>
#include <spi.h></spi.h></mysensor.h></p>
<p>#define SN “Relay”<br />
#define SV “1.0”<br />
#define CHILD_ID 1<br />
#define RELAY_PIN 3</p>
<p>MySensor gw;<br />
MyMessage msgRelay(CHILD_ID, V_STATUS);</p>
<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>
<p>void loop()<br />
{<br />
gw.process();<br />
}</p>
<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>
</article>