If minute() == X run function

Hello. I am trying to get a function to execute at precise times. Every 15 minutes, so at 00, 15, 30 and 45 minutes after the hour. I have a clock running and I tried this code, but it always runs the function no matter what.

if(minute() == '0' || '15' || '30' || '45'){
sendUpdate();
}

Any ideas? I guess I would also need to know how to make sure it runs only once during that minute instead of constantly running during that minute. Thank you.

Why character constants?
The reason it always runs is because they're all non-zero, they all evaluate to true.
Try comparisons for each .

Do you mean why the double pipes "||"? Isn't that the "OR" operator?

Your syntax for the if statement is completely wrong. You must explicitly specify each condition. Also, if the minute() function returns an integer then the comparisons are always going to fail. Try this:

if(minute() == 0 || minute() == 15 || minute == 30 || minute() == 45) {

Pete

Any ideas?

Sure. Look at the documentation for the if statement, and quit trying to invent shortcuts.

Suppose that minute() returns 14. Your if statement evaluates to

if(14 == '0' || '15' || '30' || '45')

which is equivalent to

if(false || '15' || '30' || '45')

which is equivalent to

if(false || true || true || true)

which is equivalent to

if(true)

which is why your statement always executes.

if(minute() == 0 || minute == 15 || minute() == 30 || minute() == 45)

if the correct way.

What was with all the single quotes?

I appologize for the bad syntax. As for all the single quotes, I got mixed up on when to use them. According to PaulS, I was trying to invent shortcuts. Sorry, but that was not my intent. If I knew what I was looking for, I'd have looked for it.

el_supremo, yes that worked great. Thank you for your help and I commend your skill at not belittling or being sarcastic.

There is one problem with the way the statement is constructed which can lead to very intermittent weirdness. The problem is that if you happen to be at the minute boundary when the statement is executed it could fail to detect that it should have executed sendUpdate();
For example, if the current minute is 45, but just before "minute() == 45" is evaluated the time ticks over to 46, the update won't occur.

The safest thing is to do something like this:

int now = minute();
if(now == 0 || now == 15 || now == 30 || now == 45) {

That way the time can't change while the if statement is evaluated.

Pete

Good point. So this is what I have now. Do you see any problems?

int now = minute();
if(now == 0 || now == 15 || now == 30 || now == 45 ||){
    if(now != lastMinute){
        sendUpdate();
        lastMinute = now;
    }
}

Now you can lose all the unnecessary constants, they are multiples of 15, you just need:

int now = minute () ;
if (now != lastMinute)
{
    if (now % 15 == 0)  // if divisible by 15
        sendUpdate();
    lastMinute = now;
}

Jeremy-arduino:
Do you see any problems?

The condition will remain true for a minute. How many times will you execute this code during that minute?

How many times will you execute this code during that minute?

Which part of it? The part that sends the update happens only once, when lastMinute and now are not the same.