Advertisement
kartonman

Random building lights engine shed

Dec 20th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. /*random layout module 1 engine shed*/
  2.  
  3.  
  4. //Random Lights
  5. #define Shedfront 2
  6. #define Shedmiddle 3
  7. #define Shopback 4
  8. #define Shopfront 5
  9.  
  10. //Outside Lights
  11. #define Shopdoor 7 /* a shaded entrance light made from a prewired smd led. It will
  12. turn on at night and off during the day.*/
  13.  
  14. //Constant Lights
  15. #define Shedback A1 /*This light will be on 24 hours per day. Will be 3mm led
  16. with 1 k resistor so it is not very bright*/
  17.  
  18. #define Switch A0 /*Input from daily cycle sketch. A sample sketch can be found at this link */
  19. int val = 0; // needed to declares val. The initial value is set to zero.
  20.  
  21. //********************************************
  22. void setup() {
  23. //This sequnce runs once.
  24. //Constant Lights
  25. digitalWrite(Shedback, HIGH); //The shed back light turns on and stays on.
  26.  
  27.  
  28. //random lights
  29. pinMode(Shedmiddle, OUTPUT);
  30. pinMode(Shedfront, OUTPUT);
  31. pinMode(Shopfront, OUTPUT);
  32. pinMode(Shopback, OUTPUT);
  33. pinMode(Shopdoor, OUTPUT);
  34.  
  35. pinMode(Switch, INPUT);
  36.  
  37. randomSeed(analogRead(A0)); // This makes the starting point of any random sequence random itself
  38.  
  39. }
  40.  
  41. //Routine
  42. void loop() {
  43. //each light sequnce is controlled by a function.
  44. turnonLights();
  45. turnoffLights();
  46. outsideLights();
  47. }
  48.  
  49. //**************************************************
  50. //functions
  51.  
  52. void turnonLights()
  53. {
  54. val = digitalRead(Switch);
  55. if (val == HIGH) {
  56. int Lights = random(2, 6); /*controls the lights on pins 2 thru 5. But when using random
  57. you have to add 1 to the last pin number.)*/
  58. int dlay = random(500, 1000); /* The time between lights turning on will vary between 1/2 secong and
  59. 1 second.*/
  60. digitalWrite(Lights, HIGH);
  61. delay(dlay);
  62.  
  63. }
  64.  
  65. }
  66. //**************************************************
  67. void turnoffLights() {
  68.  
  69. val = digitalRead(Switch);
  70. if (val == LOW)
  71. {
  72. int Lights = random(2, 6);
  73. int dlay = random(700, 2000);
  74. digitalWrite(Lights, LOW);
  75. delay(dlay);
  76.  
  77. }
  78. }
  79. //************************************************************
  80. void outsideLights()
  81.  
  82. {
  83. val = digitalRead(Switch);
  84. if (val == LOW) {
  85.  
  86. digitalWrite(Shopdoor, HIGH);
  87. }
  88. else {
  89. digitalWrite(Shopdoor, LOW);
  90.  
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement