Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*random layout module 1 engine shed*/
- //Random Lights
- #define Shedfront 2
- #define Shedmiddle 3
- #define Shopback 4
- #define Shopfront 5
- //Outside Lights
- #define Shopdoor 7 /* a shaded entrance light made from a prewired smd led. It will
- turn on at night and off during the day.*/
- //Constant Lights
- #define Shedback A1 /*This light will be on 24 hours per day. Will be 3mm led
- with 1 k resistor so it is not very bright*/
- #define Switch A0 /*Input from daily cycle sketch. A sample sketch can be found at this link */
- int val = 0; // needed to declares val. The initial value is set to zero.
- //********************************************
- void setup() {
- //This sequnce runs once.
- //Constant Lights
- digitalWrite(Shedback, HIGH); //The shed back light turns on and stays on.
- //random lights
- pinMode(Shedmiddle, OUTPUT);
- pinMode(Shedfront, OUTPUT);
- pinMode(Shopfront, OUTPUT);
- pinMode(Shopback, OUTPUT);
- pinMode(Shopdoor, OUTPUT);
- pinMode(Switch, INPUT);
- randomSeed(analogRead(A0)); // This makes the starting point of any random sequence random itself
- }
- //Routine
- void loop() {
- //each light sequnce is controlled by a function.
- turnonLights();
- turnoffLights();
- outsideLights();
- }
- //**************************************************
- //functions
- void turnonLights()
- {
- val = digitalRead(Switch);
- if (val == HIGH) {
- int Lights = random(2, 6); /*controls the lights on pins 2 thru 5. But when using random
- you have to add 1 to the last pin number.)*/
- int dlay = random(500, 1000); /* The time between lights turning on will vary between 1/2 secong and
- 1 second.*/
- digitalWrite(Lights, HIGH);
- delay(dlay);
- }
- }
- //**************************************************
- void turnoffLights() {
- val = digitalRead(Switch);
- if (val == LOW)
- {
- int Lights = random(2, 6);
- int dlay = random(700, 2000);
- digitalWrite(Lights, LOW);
- delay(dlay);
- }
- }
- //************************************************************
- void outsideLights()
- {
- val = digitalRead(Switch);
- if (val == LOW) {
- digitalWrite(Shopdoor, HIGH);
- }
- else {
- digitalWrite(Shopdoor, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement