You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #define FET 8
  2. #define testFET 0
  3. #define SWLIGHT 10
  4. #define SWREED 11
  5. //Switches on Pins 10, and 11
  6. //Switch 10, is light switch. Ground when switch is up (ON).
  7. //Switch 11, is magnet reed switch, Ground when door is closed.
  8. uint8_t SWLIGHTvar = 0;
  9. uint8_t SWREEDvar = 0;
  10. void setup() {
  11. pinMode(FET, OUTPUT);
  12. pinMode(SWLIGHT, INPUT);
  13. pinMode(SWREED, INPUT);
  14. }
  15. void loop() {
  16. //test the fet
  17. /* while(1){
  18. digitalWrite(FET, HIGH); // turn the LED on (HIGH is the voltage level)
  19. delay(100); // wait for a second
  20. digitalWrite(FET, LOW); // turn the LED off by making the voltage LOW
  21. delay(1000); // wait for a second
  22. }*/
  23. /* OUTLINE */
  24. //Read light switch, read magnet switch
  25. //if light switch is 5v, do nothing, wait 3 seconds
  26. //if light switch is gnd, continue
  27. //if reed switch is gnd, do nothing, wait 100 ms
  28. //if reed switch is high, continue
  29. //ring bell, sleep for 10 seconds
  30. SWLIGHTvar = digitalRead(SWLIGHT);
  31. SWREEDvar = digitalRead(SWREED);
  32. if(SWLIGHTvar == 0){
  33. if(SWREEDvar == 1){
  34. digitalWrite(FET, 1); // turn on (HIGH is the voltage level)
  35. delay(80); // wait
  36. digitalWrite(FET, 0); // turn off by making the voltage LOW
  37. delay(15000); // wait for 15 seconds
  38. }
  39. goto breakout;
  40. }
  41. //if light switch is 5v, do nothing, wait 3 seconds
  42. delay(3000);
  43. breakout:
  44. delay(100);
  45. }