diff --git a/atom.xml b/atom.xml index 6bd59ea421..e9eb59e474 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@
```c++
-/**
- * Documentation: http://www.mysensors.org
- * Support Forum: http://forum.mysensors.org
- *
- * http://www.mysensors.org/build/binary
- */
/** + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/binary + */ -#include
--#include -#include #define SN “BinarySensor”
+#include <MySensor.h> +#include <SPI.h> +#include <Bounce2.h> -
-#define SV “1.0”
-#define CHILD_ID 1
-#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch.MySensor gw;
+#define SN "BinarySensor" +#define SV "1.0" +#define CHILD_ID 1 +#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch. -
-Bounce debouncer = Bounce();
-MyMessage msg(CHILD_ID, V_TRIPPED);void setup()
+MySensor gw; +Bounce debouncer = Bounce(); +MyMessage msg(CHILD_ID, V_TRIPPED); -
-{
- gw.begin();
- gw.sendSketchInfo(SN, SV);
- // Setup the button.
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- // After setting up the button, setup debouncer.
- debouncer.attach(BUTTON_PIN);
- debouncer.interval(5);
- gw.present(CHILD_ID, S_DOOR);
- gw.send(msg.set(0));
-}void loop()
+void setup() +{ + gw.begin(); + gw.sendSketchInfo(SN, SV); + // Setup the button. + pinMode(BUTTON_PIN, INPUT_PULLUP); + // After setting up the button, setup debouncer. + debouncer.attach(BUTTON_PIN); + debouncer.interval(5); + gw.present(CHILD_ID, S_DOOR); + gw.send(msg.set(0)); +} + +void loop() +{ + if (debouncer.update()) { + // Get the update value. + int value = debouncer.read(); + // Send in the new value. + gw.send(msg.set(value == LOW ? 1 : 0)); + } +} +
-{
- if (debouncer.update()) {
- // Get the update value.
- int value = debouncer.read();
- // Send in the new value.
- gw.send(msg.set(value == LOW ? 1 : 0));
- }
-}
-```
```c++
-/*
- * Documentation: http://www.mysensors.org
- * Support Forum: http://forum.mysensors.org
- *
- * http://www.mysensors.org/build/dimmer
- */
/* + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/dimmer + */ -#include
+#include <MySensor.h> +#include <SPI.h> --#include #define SN “DimmableRGBLED”
+#define SN "DimmableRGBLED" +#define SV "1.0" +#define CHILD_ID 1 +#define LED_PIN 5 -
-#define SV “1.0”
-#define CHILD_ID 1
-#define LED_PIN 5MySensor gw;
+MySensor gw; -char rgb[7] = “ffffff”; // RGB value.
+char rgb[7] = "ffffff"; // RGB value. +int currentLevel = 0; // Current dimmer level. +MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE); +MyMessage lightMsg(CHILD_ID, V_STATUS); +MyMessage rgbMsg(CHILD_ID, V_RGB); -
-int currentLevel = 0; // Current dimmer level.
-MyMessage dimmerMsg(CHILD_ID, V_PERCENTAGE);
-MyMessage lightMsg(CHILD_ID, V_STATUS);
-MyMessage rgbMsg(CHILD_ID, V_RGB);void setup()
+void setup() +{ + gw.begin(incomingMessage); + gw.sendSketchInfo(SN, SV); + gw.present(CHILD_ID, S_RGB_LIGHT); + // Send initial values. + gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0)); + gw.send(dimmerMsg.set(currentLevel)); + gw.send(rgbMsg.set(rgb)); +} -
-{
- gw.begin(incomingMessage);
- gw.sendSketchInfo(SN, SV);
- gw.present(CHILD_ID, S_RGB_LIGHT);
- // Send initial values.
- gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0));
- gw.send(dimmerMsg.set(currentLevel));
- gw.send(rgbMsg.set(rgb));
-}void loop()
+void loop() +{ + gw.process(); +} -
-{
- gw.process();
-}void incomingMessage(const MyMessage &message) {
+void incomingMessage(const MyMessage &message) { + if (message.type == V_RGB) { + // Retrieve the RGB value from the incoming message. + // RGB LED not implemented, just a dummy print. + String hexstring = message.getString(); + hexstring.toCharArray(rgb, sizeof(rgb)); + Serial.print("Changing color to "); + Serial.println(rgb); + gw.send(rgbMsg.set(rgb)); + } -
- if (message.type == V_RGB) {
- // Retrieve the RGB value from the incoming message.
- // RGB LED not implemented, just a dummy print.
- String hexstring = message.getString();
- hexstring.toCharArray(rgb, sizeof(rgb));
- Serial.print(“Changing color to “);
- Serial.println(rgb);
- gw.send(rgbMsg.set(rgb));
- }if (message.type == V_STATUS || message.type == V_PERCENTAGE) {
+ if (message.type == V_STATUS || message.type == V_PERCENTAGE) { + // Retrieve the light status or dimmer level from the incoming message. + int requestedLevel = atoi(message.data); -
- // Retrieve the light status or dimmer level from the incoming message.
- int requestedLevel = atoi(message.data);+ // Update the gateway with the current V_STATUS and V_PERCENTAGE. + gw.send(lightMsg.set(currentLevel > 0 ? 1 : 0)); + gw.send(dimmerMsg.set(currentLevel)); + } +} +// Adjust incoming level if this is a V_LIGHT update [0 == off, 1 == on]. -requestedLevel *= (message.type == V_STATUS ? 100 : 1); + // 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 > 100 ? 100 : requestedLevel; -requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; + // Clip incoming level to valid range of 0 to 100 + requestedLevel = requestedLevel > 100 ? 100 : requestedLevel; + requestedLevel = requestedLevel < 0 ? 0 : requestedLevel; -// Change level value of LED pin. -analogWrite(LED_PIN, (int)(requestedLevel / 100. * 255)); -currentLevel = 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 > 0 ? 1 : 0)); -gw.send(dimmerMsg.set(currentLevel)); -} } ``` -
```c++
-/**
- * Documentation: http://www.mysensors.org
- * Support Forum: http://forum.mysensors.org
- *
- * http://www.mysensors.org/build/light
- */
/** + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/light + */ -#include
+#include <SPI.h> +#include <MySensor.h> +#include <BH1750.h> +#include <Wire.h> --#include -#include -#include #define SN “LightLuxSensor”
+#define SN "LightLuxSensor" +#define SV "1.0" +#define CHILD_ID 1 +unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) -
-#define SV “1.0”
-#define CHILD_ID 1
-unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)BH1750 lightSensor;
+BH1750 lightSensor; +MySensor gw; +MyMessage msg(CHILD_ID, V_LEVEL); +MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message. +uint16_t lastlux = 0; -
-MySensor gw;
-MyMessage msg(CHILD_ID, V_LEVEL);
-MyMessage msgPrefix(CHILD_ID, V_UNIT_PREFIX); // Custom unit message.
-uint16_t lastlux = 0;void setup()
+void setup() +{ + gw.begin(); + gw.sendSketchInfo(SN, SV); + gw.present(CHILD_ID, S_LIGHT_LEVEL); + lightSensor.begin(); + gw.send(msg.set(lastlux)); + gw.send(msgPrefix.set("lux")); // Set custom unit. +} -
-{
- gw.begin();
- gw.sendSketchInfo(SN, SV);
- gw.present(CHILD_ID, S_LIGHT_LEVEL);
- lightSensor.begin();
- gw.send(msg.set(lastlux));
- gw.send(msgPrefix.set(“lux”)); // Set custom unit.
-}void loop()
+void loop() +{ + uint16_t lux = lightSensor.readLightLevel(); // Get Lux value + if (lux != lastlux) { + gw.send(msg.set(lux)); + lastlux = lux; + } -
-{
- uint16_t lux = lightSensor.readLightLevel(); // Get Lux value
- if (lux != lastlux) {
- gw.send(msg.set(lux));
- lastlux = lux;
- }gw.sleep(SLEEP_TIME);
+ gw.sleep(SLEEP_TIME); +} +
-}
-```
```c++
-/*
- * Documentation: http://www.mysensors.org
- * Support Forum: http://forum.mysensors.org
- *
- * http://www.mysensors.org/build/relay
- */
/* + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * http://www.mysensors.org/build/relay + */ -#include
+#include <MySensor.h> +#include <SPI.h> --#include #define SN “Relay”
+#define SN "Relay" +#define SV "1.0" +#define CHILD_ID 1 +#define RELAY_PIN 3 -
-#define SV “1.0”
-#define CHILD_ID 1
-#define RELAY_PIN 3MySensor gw;
+MySensor gw; +MyMessage msgRelay(CHILD_ID, V_STATUS); -
-MyMessage msgRelay(CHILD_ID, V_STATUS);void setup()
+void setup() +{ + gw.begin(incomingMessage); + gw.sendSketchInfo(SN, SV); + // Initialize the digital pin as an output. + pinMode(RELAY_PIN, OUTPUT); + gw.present(CHILD_ID, S_BINARY); + gw.send(msgRelay.set(0)); +} -
-{
- gw.begin(incomingMessage);
- gw.sendSketchInfo(SN, SV);
- // Initialize the digital pin as an output.
- pinMode(RELAY_PIN, OUTPUT);
- gw.present(CHILD_ID, S_BINARY);
- gw.send(msgRelay.set(0));
-}void loop()
+void loop() +{ + gw.process(); +} -
-{
- gw.process();
-}void incomingMessage(const MyMessage &message)
+void incomingMessage(const MyMessage &message) +{ + if (message.type == V_STATUS) { + // Change relay state. + digitalWrite(RELAY_PIN, message.getBool() ? 1 : 0); + } +} +
-{
- if (message.type == V_STATUS) {
- // Change relay state.
- digitalWrite(RELAY_PIN, message.getBool() ? 1 : 0);
- }
-}
-```