Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2015
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // +-\/-+
  2. // 1|o |8 VCC/CE RED/ORANGE
  3. // YELLOW CSN 2| |7 SCK GREEN
  4. // - SENSOR 3| |6 MOSI BLUE
  5. // BLACK GND 4| |5 MISO VIOLET
  6. // +----+
  7.  
  8. #include <MySensor.h>
  9. #include <Bounce2.h>
  10.  
  11. #define NODE_ID 1
  12. #define CHILD_ID 1
  13.  
  14. MySensor gw;
  15. Bounce debouncer = Bounce();
  16. int oldValue = -1;
  17.  
  18. MyMessage msg(NODE_ID, V_TRIPPED);
  19.  
  20. void setup()
  21. {
  22. pinMode(4, INPUT);
  23. digitalWrite(4, HIGH);
  24.  
  25. debouncer.attach(4);
  26. debouncer.interval(5);
  27.  
  28. gw.begin(NULL, NODE_ID, false, 0);
  29. gw.present(CHILD_ID, S_DOOR);
  30. }
  31.  
  32. void loop()
  33. {
  34. debouncer.update();
  35. int value = debouncer.read();
  36. if (value != oldValue) {
  37. gw.send(msg.set(value==HIGH ? 1 : 0));
  38. oldValue = value;
  39. }
  40. gw.sleep(PCINT4,CHANGE, 0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement