Hello guys,
first of all i'd like to tell you that i'm a total beginner when it comes to programming in general. I have some basic understanding of electronics but that's about it. Arduino has always fascinated me though.
My father and i are building a model railway. We would like to control the lights by using a Arduino. Our idea is as follows:
-
Main lights of the room stay on for about 10 minutes which simulates daytime.
-
When the 10 minutes are over, it's time to simulate night mode, so the relay kicks in and turns off the main lights of the room.
-
A couple of seconds later all the lights of the model railway should light up by using seperate relays, BUT (and here is the tricky part) it should happen in stages. So let's say our model railway is divided in 8 'modules' which should randomly switch on every 1 second. So that it simulates a realistic way of city lighting during the evening instead of just turning off the main light, and switching on all the model railway lights all together.
-
All the lights stay on for a good 5 minutes until the whole loop starts again and it becomes day time again.
Alright, i've gotten this far, by using delays in between the switching of the seperate relays. It worked well.
But, i'd like to have 3 buttons on the control panel side of the railway. One for never ending daytime (work light), one for never ending nighttime, and the last one to resume the program of 10 minutes daytime, 5 minutes nighttime.
I tried putting the button in the beginning of the loop, but as expected they don't work anymore once the loop continues and is hold up by the delays which slow everything down.
Now, how do i do this? Here's the original (working) code of the first test without the buttons.
int Relay1 = 12;
int Relay2 = 11;
int Relay3 = 10;
int Relay4 = 9;
int Relay5 = 8;
int Relay6 = 7;int Mainlight = 2;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);pinMode(Mainlight, OUTPUT);
}// the loop routine runs over and over again forever:
void loop() {
digitalWrite(Mainlight, LOW);
delay(2000);digitalWrite(Relay5, HIGH);
delay(1000);
digitalWrite(Relay2, HIGH);
delay(1000);
digitalWrite(Relay4, HIGH);
delay(1000);
digitalWrite(Relay1, HIGH);
delay(1000);
digitalWrite(Relay6, HIGH);
delay(1000);
digitalWrite(Relay3, HIGH);
delay(5000);digitalWrite(Relay5, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay4, LOW);
digitalWrite(Relay1, LOW);
digitalWrite(Relay6, LOW);
digitalWrite(Relay3, LOW);digitalWrite(Mainlight, HIGH);
delay(5000);}
Thanks in advance! It would help us a lot!