Skip to content

Commit

Permalink
Update RelayActuator example (#973)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mfalkvidd authored and henrikekblad committed Nov 17, 2017
1 parent 1e33059 commit 506d235
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/RelayActuator/RelayActuator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

#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 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


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
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
Expand All @@ -67,7 +67,7 @@ void presentation()
// Send the sketch version information to the gateway and Controller
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)
present(sensor, S_BINARY);
}
Expand All @@ -84,7 +84,7 @@ void receive(const MyMessage &message)
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// 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
saveState(message.sensor, message.getBool());
// Write some debug info
Expand Down

0 comments on commit 506d235

Please sign in to comment.