aarondc:
Arrch:
int hour();
int minute();
int seconds();
These aren't variables, these are function prototypes that take no arguments and return an int.
aarondc:
you have to declare the variables as int, not int function.
so:
int hours, minutes, seconds.
NOT
int hour();
int minute();
int second();
This is the solution to your "lvalue required ..." compiler errors.
the code has been replaced in the first post, and I changed it
system
June 24, 2013, 4:12am
22
now make it the same through the program.
if (minute()>59) {
should say
if (minute>59) {
etc.
remove the () from every occurrence of hour, minute and second.
system
June 24, 2013, 4:14am
23
the code has been replaced in the first post, and I changed it
Do NOT do that. We need to be able to compare the code you have now with the code you had then, to make sure that you made the changes correctly, and did not screw something else up.
aarondc:
now make it the same through the program.
if (minute()>59) {
should say
if (minute>59) {
etc.
remove the () from every occurrence of hour, minute and second.
I fixed all that, but now I get "expected unqualified-id before numeric constant" on the
int hours, minutes, seconds
but its only if i have
if (seconds>59)
{
minutes++;
seconds=0;
}
but I don't get any error on the same code but hours instead of minutes, and minutes instead of seconds
system
June 24, 2013, 4:24am
25
Better post the whole code in a new post so we can see more clearly what the issue is. Your copy + paste is not working, as it left off the ; from the
int hours, minutes, seconds
line, which was present in the OP.
most up dated code:
#include <Time.h>
int led1 = 11;
int led2 = 10;
int led3 = 9;
int led4 = 6;
int hours, minutes, seconds;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop()
{
time_t t= now();
while (exit == false)
if (seconds>59) {
minutes++;
seconds=0
if (minutes>59) {
hours++;
minutes=0;}
if (minutes>9 && seconds>9) {
cout << hours << ":" << minutes << ":" << seconds;}
if (minutes<10 && seconds<10) {
cout << hours << ":0" << minutes << ":0" << seconds;}
if (minutes<10 && seconds>9) {
cout << hours << ":0" << minutes << ":" << seconds;}
if (minutes>9 && seconds<10) {
cout << hours << ":" << minutes << ":0" << seconds;}
sleep(1000)
seconds++;
if hours>=8 analogWrite(led1) {
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=5)
analogWrite(led1, fadeValue);
delay(30);}
if hours>=9 analogWrite(led2) {
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=5)
analogWrite(led2, fadeValue);
delay(30);}
if hours>=1900 analogWrite(led3) {
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=5)
analogWrite(led3, fadeValue);
delay(30);}
if hours>=2000 analogWrite(led4) {
for(int fadeValue = 0 ; fadeValue <=255; fadeValue +=5)
analogWrite(led4, fadeValue);
delay(30);}
if hours<=8 && minutes<=15 analogWrite(led1) {
for(int fadeValue = 255 ; fadeValue >=255; fadeValue -=5)
analogWrite(led1, fadeValue);
delay(30);}
if hours<=1900 && minutes<=15 analogWrite(led2) {
for(int fadeValue = 255 ; fadeValue >=255; fadeValue -=5)
analogWrite(led1, fadeValue);
delay(30);}
if hours<= && minutes<=15 analogWrite(led3) {
for(int fadeValue = 255 ; fadeValue >=255; fadeValue -=5)
analogWrite(led1, fadeValue);
delay(30);}
if hours<=200 && minutes<=15 analogWrite(led4) {
for(int fadeValue = 255 ; fadeValue >=255; fadeValue -=5)
analogWrite(led1, fadeValue);
delay(30);}
}
system
June 24, 2013, 4:35am
27
while (exit == false)
This concerns me. Where did you define "exit"?
system
June 24, 2013, 4:41am
28
seconds=0
sleep(1000)
Some statements need ; on the end...
Putting each { and } on a new line, and using Tools + Auto Format will make that mess more readable.
system
June 24, 2013, 4:44am
29
It looks like your entire while loop
while (exit == false)
if (seconds>59) {
minutes++;
seconds=0
if (minutes>59) {
hours++;
minutes=0;}
is only going to run once a minute. Formatting your code properly will help a lot in working out why it's not working.
Please do not amend the code in the original post. It makes the replies that follow meaningless.
Post updated code in new posts.
You are missing curly braces. And what is this supposed to do?
while (exit == false)
system
June 24, 2013, 4:57am
31
It's a conditional while loop using an undefined variable that never gets set or changed.
exit is a function. This compiles but doesn't do anything useful:
void setup ()
{
} // end of setup
void loop ()
{
while (exit == false) ;
} // end of loop
So I was wondering what the actual intent was?
system
June 24, 2013, 5:23am
33
[quote author=Nick Gammon link=topic=173541.msg1290104#msg1290104 date=1372051296]
So I was wondering what the actual intent was?
[/quote]
I know what it does
I am guessing the intent was to keep looping until he determined an exit condition.
[quote author=PaulS link=topic=173541.msg1290074#msg1290074 date=1372048877]
[code] seconds=0
sleep(1000)
Some statements need ; on the end...
Putting each { and } on a new line, and using Tools + Auto Format will make that mess more readable.
[/quote]
I know what :, {, and } do, but dont understand when to use them. I am assuming that the ";" would be used as a period is used in english writing, and the { } are used as kind of like containers, so the program knows that every thing inside of them needs to run together.
[code while (exit == false)[/code]
I seen someone use in clock tutorial. honestly not sure if I need it. I'm on my work computer so i dont have my project with me and I cant make changes.
PaulS:
seconds=0
sleep(1000)
Some statements need ; on the end...
Putting each { and } on a new line, and using Tools + Auto Format will make that mess more readable.
is it better to write:
if (seconds>59)
{
minute++;
seconds=0;
}
vs
if (seconds>59){
minutes++;
seconds=0;}
Use this one:
if (seconds>59)
{
minute++;
seconds=0;
}
My question is why do you load the time library, actually read the time but then never use it?
system
June 24, 2013, 1:54pm
37
is it better to write:
In my opinion, yes.
There are two schools of thought as to how that snippet of code should be arranged.
if (seconds>59)
{
minute++;
seconds=0;
}
or:
if (seconds>59) {
minute++;
seconds=0;
}
Note the neither method allows for the } on the same line as any other code. Note, too, that in the second method the { is separated from the statement by a space.
Your proposed alternative violates both of these rules.
Putting the { on a new line takes one more line, but the block is much more clearly defined, in my opinion.
Jimmy60:
Use this one:
if (seconds>59)
{
minute++;
seconds=0;
}
My question is why do you load the time library, actually read the time but then never use it?
I thought the "time_t t = now();" needed the "time.h" library.
I thought the "time_t t = now();" needed the "time.h" library.
It does, but other than reading the time you never use it.
Jimmy60:
I thought the "time_t t = now();" needed the "time.h" library.
It does, but other than reading the time you never use it.
I thought the
int hours, minutes, seconds;
used the time.h library for the veriables, so that my program can refer back to the time value of ecach variable for "if" arguments.