Update RelayActuator example (#973)
Based on feedback from skywatch, https://forum.mysensors.org/post/78896 We'll need to update the wiring instructions on https://www.mysensors.org/build/relay as well.
This commit is contained in:
committed by
Henrik Ekblad
parent
1e3305959e
commit
506d23581d
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
|
|
||||||
#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
|
#define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
|
||||||
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
|
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
|
||||||
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
|
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
|
||||||
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
|
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
|
|
||||||
void before()
|
void before()
|
||||||
{
|
{
|
||||||
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
|
for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
|
||||||
// Then set relay pins in output mode
|
// Then set relay pins in output mode
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
// Set relay to last known state (using eeprom storage)
|
// Set relay to last known state (using eeprom storage)
|
||||||
@@ -67,7 +67,7 @@ void presentation()
|
|||||||
// Send the sketch version information to the gateway and Controller
|
// Send the sketch version information to the gateway and Controller
|
||||||
sendSketchInfo("Relay", "1.0");
|
sendSketchInfo("Relay", "1.0");
|
||||||
|
|
||||||
for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
|
for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
|
||||||
// Register all sensors to gw (they will be created as child devices)
|
// Register all sensors to gw (they will be created as child devices)
|
||||||
present(sensor, S_BINARY);
|
present(sensor, S_BINARY);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ void receive(const MyMessage &message)
|
|||||||
// We only expect one type of message from controller. But we better check anyway.
|
// We only expect one type of message from controller. But we better check anyway.
|
||||||
if (message.type==V_STATUS) {
|
if (message.type==V_STATUS) {
|
||||||
// Change relay state
|
// Change relay state
|
||||||
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
|
digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
|
||||||
// Store state in eeprom
|
// Store state in eeprom
|
||||||
saveState(message.sensor, message.getBool());
|
saveState(message.sensor, message.getBool());
|
||||||
// Write some debug info
|
// Write some debug info
|
||||||
|
|||||||
Reference in New Issue
Block a user