Go Down

Topic: light control unit code problems (Read 2712 times) previous topic - next topic

Joes

hi there
i have tried to make a code for my arduino what has 4 LED's the first one turns on waits 15mins turns back off and a delay for 1 second and so on then returns to the start. but seem to be getting error messages when uploading i am still a newbe to this so i expect someone will look at this and laugh and tell me i did a stupid mistake.  :D

any help will be grateful thanks

Code: [Select]

// 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) //seting 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
  digital(1000); //turn all off for 1 second
 
}


AWOL

#1
Oct 20, 2011, 10:44 pm Last Edit: Oct 20, 2011, 11:19 pm by AWOL Reason: 1
That code won't compile, so can't possibly run.

"output" is not the same as "OUTPUT".
"digitalwrite" is not the same as "digitalWrite".
"A light" is not the same as "A_light"
Needs more semicolons.

Simplify, try smaller sketches, experiment until you get code to compile, then try to run it.

To save time when it comes to debugging, compress time:
Code: [Select]
#ifdef DEBUG
#define LONG_DELAY (15UL * 60UL * 1000UL)
#define SHORT_DELAY (1000UL)
#else

#define LONG_DELAY (15UL * 60UL * 10UL)
#define SHORT_DELAY (100UL)

#endif
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Joes

now i have got it wrapped around my hedad now and all confused lol

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Joes

confused dont no how to sort this out

AWOL

#5
Oct 20, 2011, 11:27 pm Last Edit: Oct 20, 2011, 11:31 pm by AWOL Reason: 1
Use the compiler and my comments above to help you make corrections.

This compiles.
Code: [Select]
#define A_light 13 // Light A on pin 13
void setup()
{
  pinMode(A_light, OUTPUT);
}

void loop ()
{
  digitalWrite(A_light, HIGH); //turn A light on
  delay(900000UL); // wait for 15 mins
  digitalWrite(A_light, LOW); // turn A light off
  delay(1000UL);  // turn all off for 1 second
}

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Joes

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
Code: [Select]


// 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

Code: [Select]


// 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
 
}


AWOL

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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Joes

i know this will not work but am i barking up the right tree
Code: [Select]

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
 
}


PaulS

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

Now, knock it off. The barking is annoying.

Joes

i have stopped barking now  :D
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

wildbill

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.

Joes

hi got it all working now thanks all for your help  :smiley-mr-green:

Joes

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
Code: [Select]



// 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
 
}




AWOL

The semicolons on the if statements can't be helping
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up