Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Enable debug prints to serial monitor
  2. #define MY_DEBUG
  3. // Enable serial gateway
  4. #define MY_GATEWAY_SERIAL
  5. #define MY_BAUD_RATE 115200
  6. // Set blinking period
  7. #define MY_DEFAULT_LED_BLINK_PERIOD 300
  8. #define MY_NODE_ID 1
  9. #include <MySensors.h>
  10. #include <SPI.h>
  11.  
  12. uint32_t SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
  13. #define RELAY_1 5 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
  14. #define NUMBER_OF_RELAYS 1 // Total number of attached relays
  15. #define RELAY_ON 1  // GPIO value to write to turn on attached relay
  16. #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
  17. #define CHILD_ID_LIGHT_0 0
  18. #define OBWOD_1_PIN 8
  19.  
  20. void setup()
  21. {
  22.   for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
  23.     // Then set relay pins in output mode
  24.     pinMode(pin, OUTPUT);
  25.   }
  26.   // Setup locally attached sensors
  27.    pinMode(OBWOD_1_PIN, INPUT_PULLUP);
  28.   // presentation();
  29. }
  30.  
  31. MyMessage msg(CHILD_ID_LIGHT_0, V_STATUS);
  32.  
  33. void presentation()
  34. {
  35.   // Present locally attached sensors
  36.   // Send the sketch version information to the gateway and Controller
  37.   sendSketchInfo("Oswietlenie", "1.0");
  38.   present(CHILD_ID_LIGHT_0, S_BINARY);
  39. }
  40.  
  41. void loop()
  42. {
  43.   bool StanObwodu1 = digitalRead(OBWOD_1_PIN)==LOW;
  44.     //send(msg.set(StanObwodu1?"1":"0"));
  45.   send(msg.set(StanObwodu1));
  46.     // sleep(digitalPinToInterrupt(OBWOD_1_PIN), CHANGE, SLEEP_TIME);
  47.   wait(20);
  48.  }
  49.  
  50. void receive(const MyMessage &message)
  51. {
  52.   // We only expect one type of message from controller. But we better check anyway.
  53.   if (message.type==V_STATUS) {
  54.     // Change relay state
  55.     digitalWrite(message.sensor-1+RELAY_1, HIGH);
  56.     wait(20);
  57.     digitalWrite(message.sensor-1+RELAY_1, LOW);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement