light control unit code problems

hi there i got it working thanks for the help i only scanned over what you said in the first place after slowing down a bit i saw what you were getting at

this is the current code

// Example 01: Lighting Timer

#define A_light 13 // Light A on pin 13
#define B_light 12 // Light B on pin 12
#define C_light 11 // Light C on pin 11
#define D_light 10 // Light D on pin 10


void setup() {
  pinMode(A_light, OUTPUT);
  pinMode(B_light, OUTPUT); //Setting the digital
  pinMode(C_light, OUTPUT); // pin's as output
  pinMode(D_light, OUTPUT);
}

void loop ()
{
  digitalWrite(A_light, HIGH); //turn A light on
  delay(900000); // wait for 15 mins
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
  digitalWrite(B_light, HIGH); //turn B light on
  delay(900000); //waint for 15mins
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
  digitalWrite(C_light, HIGH); // turn C light on
  delay(900000); // turn all off for 1 second
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
  digitalWrite(D_light, HIGH); // turn D light on
  delay(900000); // D light off
  digitalWrite(D_light, LOW); // turn D light off
  delay(1000); //turn all off for 1 second
  
}

but now i would like to add a switch to alter the 15minute delay time so when buttons not pushed there will be a 15 minute delay between them all and when the button is pressed there will be a 30 min gap between them all i have started to adjust code as far as i am able to any help would be appreciated

// Example 01: Lighting Timer

#define A_light 13 // Light A on pin 13
#define B_light 12 // Light B on pin 12
#define C_light 11 // Light C on pin 11
#define D_light 10 // Light D on pin 10
#define button 7  //   Button on pin 7


void setup() {
  pinMode(A_light, OUTPUT);
  pinMode(B_light, OUTPUT); //Setting the digital
  pinMode(C_light, OUTPUT); // pin's as output
  pinMode(D_light, OUTPUT);
  pinMode(button, INPUT);  //setting as an input
}

void loop ()
{
  digitalWrite(A_light, HIGH); //turn A light on
  delay(900000); // wait for 15 mins
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
  digitalWrite(B_light, HIGH); //turn B light on
  delay(900000); //waint for 15mins
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
  digitalWrite(C_light, HIGH); // turn C light on
  delay(900000); // turn all off for 1 second
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
  digitalWrite(D_light, HIGH); // turn D light on
  delay(900000); // D light off
  digitalWrite(D_light, LOW); // turn D light off
  delay(1000); //turn all off for 1 second
  
}

You're going to have to change the constants in the delays for variables.
Watch out for 'int' arithmetic overflowing/wrapping with such large numbers.

i know this will not work but am i barking up the right tree

void loop ()
{
  val = digitalRead(button); //read input value and store it
  
  digitalWrite(A_light, HIGH); //turn A light on
  delay(900000); // wait for 15 mins
  if (val == HIGH) {
    delay(900000); // delay for 30 mins if button is HIGH
  }
  {  
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
  digitalWrite(B_light, HIGH); //turn B light on
  delay(900000); //waint for 15mins
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
  digitalWrite(C_light, HIGH); // turn C light on
  delay(900000); // turn all off for 1 second
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
  digitalWrite(D_light, HIGH); // turn D light on
  delay(900000); // D light off
  digitalWrite(D_light, LOW); // turn D light off
  delay(1000); //turn all off for 1 second
  
}

Except for the incorrect number of {, yes, you are barking up the right tree.

Now, knock it off. The barking is annoying.

i have stopped barking now :smiley:
i have played with it a few times now and still cant get this to work sorry if im being a little bit thick.

thanks Joe

First implement Awol's advice: replace all 900000 with 900000UL The compiler will try to interpret it as a 16 bit integer constant otherwise, which won't fit and will give you odd results.

Then - what isn't working?

Also, for the test phase, you might consider using 90000UL instead - it's still large enough to need the UL, but you can run through the program without dying of boredom.

hi got it all working now thanks all for your help :grin:

hi there again
i have made a few adjustments and added an extra 4 switches to turn off any one of the 4 lights but letting the sequence carry on i can upload this code to my controller but i cant seem to get any of the four switches to work dont know if any one notices any faults in this if so please tell me
thanks

// Example 02: Lighting Timer  26/10/2011

#define A_light 13     // Light A on pin 13
#define B_light 12     // Light B on pin 12
#define C_light 11     // Light C on pin 11
#define D_light 10     // Light D on pin 10
#define time_button 7  // Button on pin 7
#define A_light_button  1// Light A button
#define B_light_button  2// Light B button
#define C_light_button  3// Light C button
#define D_light_button  4// Light D button

int timebutton = 0;     
int buttonA = 0;      
int buttonB = 0;         // val will be used to store the
int buttonC = 0;         // state of the input pin
int buttonD = 0;

void setup() {
  pinMode(A_light, OUTPUT);
  pinMode(B_light, OUTPUT);       //Setting the digital
  pinMode(C_light, OUTPUT);       // pin's as output
  pinMode(D_light, OUTPUT);
  pinMode(time_button, INPUT);   
  pinMode(A_light_button, INPUT);
  pinMode(B_light_button, INPUT);
  pinMode(C_light_button, INPUT); // Setting as an input
  pinMode(D_light_button, INPUT);
}

void loop ()
{
timebutton = digitalRead(time_button); //read input value and store it
buttonA = digitalRead(A_light_button); //read input value and store it
buttonB = digitalRead(B_light_button); //read input value and store it
buttonC = digitalRead(C_light_button); //read input value and store it
buttonD = digitalRead(D_light_button); //read input value and store it

delay(1000); //turn all off for 1 second
if (buttonA == HIGH); { // if button A is on do the following
  digitalWrite(A_light, HIGH); } //turn A light on
  delay(9000UL); // wait for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  }   
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
if (buttonB == HIGH); { // if button B is on do the following
  digitalWrite(B_light, HIGH); } //turn B light on
  delay(9000UL); //waint for 15mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } 
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
if (buttonC == HIGH); { // if button C is on do the following
  digitalWrite(C_light, HIGH); } // turn C light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } 
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
if (buttonD == HIGH); { // if button D is on do the following
  digitalWrite(D_light, HIGH); } // turn D light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } 
  digitalWrite(D_light, LOW); // turn D light off
  
}

The semicolons on the if statements can't be helping

o yer i see

i just tried this and still have the same problem

// Example 02: Lighting Timer  26/10/2011

#define A_light 13     // Light A on pin 13
#define B_light 12     // Light B on pin 12
#define C_light 11     // Light C on pin 11
#define D_light 10     // Light D on pin 10
#define time_button 7  // Button on pin 7
#define A_light_button  1// Light A button
#define B_light_button  2// Light B button
#define C_light_button  3// Light C button
#define D_light_button  4// Light D button

int timebutton = 0;     
int buttonA = 0;      
int buttonB = 0;         // val will be used to store the
int buttonC = 0;         // state of the input pin
int buttonD = 0;

void setup() {
  pinMode(A_light, OUTPUT);
  pinMode(B_light, OUTPUT);       //Setting the digital
  pinMode(C_light, OUTPUT);       // pin's as output
  pinMode(D_light, OUTPUT);
  pinMode(time_button, INPUT);   
  pinMode(A_light_button, INPUT);
  pinMode(B_light_button, INPUT);
  pinMode(C_light_button, INPUT); // Setting as an input
  pinMode(D_light_button, INPUT);
}

void loop ()
{
timebutton = digitalRead(time_button); //read input value and store it
buttonA = digitalRead(A_light_button); //read input value and store it
buttonB = digitalRead(B_light_button); //read input value and store it
buttonC = digitalRead(C_light_button); //read input value and store it
buttonD = digitalRead(D_light_button); //read input value and store it

delay(1000); //turn all off for 1 second
if (buttonA == HIGH); { // if button A is on do the following
  digitalWrite(A_light, HIGH);  //turn A light on
  delay(9000UL); // wait for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  }   }
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
if (buttonB == HIGH); { // if button B is on do the following
  digitalWrite(B_light, HIGH);  //turn B light on
  delay(9000UL); //waint for 15mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
if (buttonC == HIGH); { // if button C is on do the following
  digitalWrite(C_light, HIGH);  // turn C light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
if (buttonD == HIGH); { // if button D is on do the following
  digitalWrite(D_light, HIGH);  // turn D light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(D_light, LOW); // turn D light off
  
}

You still have the same semicolons

look again i have changed where the semicolons close on the end of each section

No, you look again.
And when you've sorted it, post again

there is a subtle difference i just got misses to check as well lol
prob not the difference you hoping for tho lol

Sorry, I don't understand your last post.

ok so where do you think i have gone wrong as i thought i had all the semicolons in the right place obviously i havent?

Look at your if statements (I can't because you haven't posted your code).
Is there a semicolon there?
Do you think it should be there?
If so, leave it there, otherwise, remove it.

i would say leve it there but i don't have much experience of this

// Example 02: Lighting Timer  26/10/2011

#define A_light 13     // Light A on pin 13
#define B_light 12     // Light B on pin 12
#define C_light 11     // Light C on pin 11
#define D_light 10     // Light D on pin 10
#define time_button 7  // Button on pin 7
#define A_light_button  1// Light A button
#define B_light_button  2// Light B button
#define C_light_button  3// Light C button
#define D_light_button  4// Light D button

int timebutton = 0;     
int buttonA = 0;      
int buttonB = 0;         // val will be used to store the
int buttonC = 0;         // state of the input pin
int buttonD = 0;

void setup() {
  pinMode(A_light, OUTPUT);
  pinMode(B_light, OUTPUT);       //Setting the digital
  pinMode(C_light, OUTPUT);       // pin's as output
  pinMode(D_light, OUTPUT);
  pinMode(time_button, INPUT);   
  pinMode(A_light_button, INPUT);
  pinMode(B_light_button, INPUT);
  pinMode(C_light_button, INPUT); // Setting as an input
  pinMode(D_light_button, INPUT);
}

void loop ()
{
timebutton = digitalRead(time_button); //read input value and store it
buttonA = digitalRead(A_light_button); //read input value and store it
buttonB = digitalRead(B_light_button); //read input value and store it
buttonC = digitalRead(C_light_button); //read input value and store it
buttonD = digitalRead(D_light_button); //read input value and store it

delay(1000); //turn all off for 1 second
if (buttonA == HIGH); { // if button A is on do the following
  digitalWrite(A_light, HIGH);  //turn A light on
  delay(9000UL); // wait for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  }   }
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000);  // turn all off for 1 second
if (buttonB == HIGH); { // if button B is on do the following
  digitalWrite(B_light, HIGH);  //turn B light on
  delay(9000UL); //waint for 15mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(B_light, LOW); //turn B ligt off
  delay(1000); // turn all off for 1 second
if (buttonC == HIGH); { // if button C is on do the following
  digitalWrite(C_light, HIGH);  // turn C light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(C_light, LOW); // turn C light off
  delay(1000); //turn all off for 1 second
if (buttonD == HIGH); { // if button D is on do the following
  digitalWrite(D_light, HIGH);  // turn D light on
  delay(9000UL); // waint for 15 mins
  if (timebutton == HIGH) {
    delay(900000UL); // delay for an additional 15 mins if HIGH
  } }
  digitalWrite(D_light, LOW); // turn D light off
  
}

Take a look at the Arduino reference for if: http://arduino.cc/en/Reference/If. Compare yours, with particular reference to semicolons, to the ones you will see there. There is a very important difference.

I don't know what "leve" means.
Ok look at "if (buttonA == HIGH);"
What do you think I'm going on about?
(Hint: semicolon)