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.

74 lines
1.7 KiB

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