0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« on: October 20, 2011, 03:40:02 pm » |
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.  any help will be grateful thanks // 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 }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: October 20, 2011, 03:44:23 pm » |
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: #ifdef DEBUG #define LONG_DELAY (15UL * 60UL * 1000UL) #define SHORT_DELAY (1000UL) #else
#define LONG_DELAY (15UL * 60UL * 10UL) #define SHORT_DELAY (100UL)
#endif
|
|
|
|
« Last Edit: October 20, 2011, 04:19:11 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #2 on: October 20, 2011, 04:20:08 pm » |
now i have got it wrapped around my hedad now and all confused lol
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: October 20, 2011, 04:21:41 pm » |
I don't know what that means.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #4 on: October 20, 2011, 04:25:58 pm » |
confused dont no how to sort this out
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: October 20, 2011, 04:27:15 pm » |
Use the compiler and my comments above to help you make corrections. This compiles. #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 }
|
|
|
|
« Last Edit: October 20, 2011, 04:31:19 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #6 on: October 21, 2011, 12:05:15 pm » |
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 }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: October 21, 2011, 12:29:01 pm » |
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.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #8 on: October 21, 2011, 01:43:00 pm » |
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 }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35590
Seattle, WA USA
|
 |
« Reply #9 on: October 21, 2011, 07:10:29 pm » |
Except for the incorrect number of {, yes, you are barking up the right tree.
Now, knock it off. The barking is annoying.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #10 on: October 22, 2011, 05:45:55 am » |
i have stopped barking now  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
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2354
|
 |
« Reply #11 on: October 22, 2011, 06:20:00 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #12 on: October 22, 2011, 01:35:43 pm » |
hi got it all working now thanks all for your help 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 236
Arduino rocks
|
 |
« Reply #13 on: October 26, 2011, 02:55:55 pm » |
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 }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #14 on: October 26, 2011, 03:00:54 pm » |
The semicolons on the if statements can't be helping
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|