Add example sketches

* Add binary sensor sketch.
* Add light sketch.
* Add sensor sketch.
* Add switch sketch.
* Change example yaml to default value for optimistic setting.
This commit is contained in:
MartinHjelmare 2016-04-13 17:59:13 +02:00
parent 9b69b78bcf
commit 9e4a635494
5 changed files with 222 additions and 6 deletions

View file

@ -2,7 +2,7 @@
layout: page
title: "MySensors Binary Sensor"
description: "Instructions how to integrate MySensors binary sensors into Home Assistant."
date: 2016-02-28 01:20 +0100
date: 2016-04-13 14:20 +0100
sidebar: true
comments: false
sharing: true
@ -36,5 +36,53 @@ S_MOISTURE | V_TRIPPED
For more information, visit the [serial api] of MySensors.
### {% linkable_title Example sketch %}
```c++
/**
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/binary
*/
#include <MySensor.h>
#include <SPI.h>
#include <Bounce2.h>
#define SN "BinarySensor"
#define SV "1.0"
#define CHILD_ID 1
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch.
MySensor gw;
Bounce debouncer = Bounce();
MyMessage msg(CHILD_ID, V_TRIPPED);
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));
}
}
```
[main component]: /components/mysensors/
[serial api]: https://www.mysensors.org/download/serial_api_15