Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enable debug prints to serial monitor
- #define MY_DEBUG
- // Enable serial gateway
- #define MY_GATEWAY_SERIAL
- #define MY_BAUD_RATE 115200
- // Set blinking period
- #define MY_DEFAULT_LED_BLINK_PERIOD 300
- #define MY_NODE_ID 1
- #include <MySensors.h>
- #include <SPI.h>
- uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
- #define RELAY_1 5 // 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
- #define CHILD_ID_LIGHT_0 0
- #define OBWOD_1_PIN 8
- void setup()
- {
- for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
- // Then set relay pins in output mode
- pinMode(pin, OUTPUT);
- }
- // Setup locally attached sensors
- pinMode(OBWOD_1_PIN, INPUT_PULLUP);
- // presentation();
- }
- MyMessage msg(CHILD_ID_LIGHT_0, V_STATUS);
- void presentation()
- {
- // Present locally attached sensors
- // Send the sketch version information to the gateway and Controller
- sendSketchInfo("Oswietlenie", "1.0");
- present(CHILD_ID_LIGHT_0, S_BINARY);
- }
- void loop()
- {
- bool StanObwodu1 = digitalRead(OBWOD_1_PIN)==LOW;
- //send(msg.set(StanObwodu1?"1":"0"));
- send(msg.set(StanObwodu1));
- // sleep(digitalPinToInterrupt(OBWOD_1_PIN), CHANGE, SLEEP_TIME);
- wait(20);
- }
- 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, HIGH);
- wait(20);
- digitalWrite(message.sensor-1+RELAY_1, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement