41
41
42
42
#include < MySensors.h>
43
43
44
- #define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
44
+ #define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
45
45
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
46
46
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
47
47
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
48
48
49
49
50
50
void before ()
51
51
{
52
- for (int sensor=1 , pin=RELAY_1 ; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
52
+ for (int sensor=1 , pin=RELAY_PIN ; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
53
53
// Then set relay pins in output mode
54
54
pinMode (pin, OUTPUT);
55
55
// Set relay to last known state (using eeprom storage)
@@ -67,7 +67,7 @@ void presentation()
67
67
// Send the sketch version information to the gateway and Controller
68
68
sendSketchInfo (" Relay" , " 1.0" );
69
69
70
- for (int sensor=1 , pin=RELAY_1 ; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
70
+ for (int sensor=1 , pin=RELAY_PIN ; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
71
71
// Register all sensors to gw (they will be created as child devices)
72
72
present (sensor, S_BINARY);
73
73
}
@@ -84,7 +84,7 @@ void receive(const MyMessage &message)
84
84
// We only expect one type of message from controller. But we better check anyway.
85
85
if (message.type ==V_STATUS) {
86
86
// Change relay state
87
- digitalWrite (message.sensor -1 +RELAY_1 , message.getBool ()?RELAY_ON:RELAY_OFF);
87
+ digitalWrite (message.sensor -1 +RELAY_PIN , message.getBool ()?RELAY_ON:RELAY_OFF);
88
88
// Store state in eeprom
89
89
saveState (message.sensor , message.getBool ());
90
90
// Write some debug info
0 commit comments