Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. //--- Photon Reed Switch ---//
  2.  
  3. int led = D7; // LED is connected to D0
  4. int reedSwitch = D4; // Reed Switch is connected to D4 and GROUND
  5.  
  6. // This routine runs only once upon reset
  7. void setup()
  8. {
  9. pinMode(led, OUTPUT); // Initialize D7 pin as output for the Photon's LED
  10. pinMode(reedSwitch, INPUT_PULLUP); // Initialize D4 pin as input with an internal pull-up resistor
  11. }
  12.  
  13. // This routine loops forever
  14. void loop()
  15. {
  16. int reedSwitchState;
  17.  
  18. reedSwitchState = digitalRead(reedSwitch);
  19.  
  20. if(reedSwitchState == HIGH) // HIGH = Door is closed
  21. { // If we push down on the push button
  22. digitalWrite(led, HIGH); // Turn ON the LED
  23. }
  24. else // LOW = Door is open
  25. {
  26. digitalWrite(led, LOW); // Turn OFF the LED
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement