timer switching state

hi all
i'm having difficulty with a project i'm doing
i need to turn an led off if its been on for 5 mins and keep it off for 5 mins more

//t1=runtime;
//if(t1>=t1+300)
//{
//compressorpin = LOW; // Turn it off
//delay(300);
//}
this is what im trying but not working

It is impossible to help with what you have posted. Please post the entire program using code tags (the </> icon). That said, this can never work:

t1=runtime;
if(t1>=t1+300)

As using t1 on both sides of the compare is just silliness.

if(t1>=t1+300)

I want you to think hard about this line for a minute. How can t1 possibly be greater than t1 plus some number. Can you think of any number you could put in for t1 where this would be true? can you think of any number that is greater than a number that is 300 more? I certainly can't.

Delta_G:

if(t1>=t1+300)

I want you to think hard about this line for a minute. How can t1 possibly be greater than t1 plus some number. Can you think of any number you could put in for t1 where this would be true? can you think of any number that is greater than a number that is 300 more? I certainly can't.

With the magic of integer math and overflows... yes, it's possible.
If t1 is a 16-bit unsigned integer: anything 65236-65535 would work.
For a 16-bit signed integer it's about half that number.

Do you think that is the OP's intent?

I know integers overflow, but I was trying to keep it simple for the noobie. Thanks for adding confusion with pedantry.

Delta_G:
Do you think that is the OP's intent?

I know integers overflow, but I was trying to keep it simple for the noobie. Thanks for adding confusion with pedantry.

You ask an interesting question, you get an answer. Don't complain.

Delta_G:
Do you think that is the OP’s intent?

I know integers overflow, but I was trying to keep it simple for the noobie. Thanks for adding , pedantry.

Isn’t all programming an excessive attention to pedantry ?

Yes but I'm actually just trying to help this person we the fault in their code. Now we've added extra stuff that this guy may or may not understand but definitely doesn't have any bearing on his issue.

Is your purpose here to help people learn to code or to find interesting things to point out to other programmers? They have sites for that sort of thing too.

Are you here to help this cat fix his program? Or to try to show off?

If you want to show off there are better places for that. You don't walk into a kindergarten spouting trivia to try to show off how smart you are do you? Sure you are smarter than the kindergarteners. That's nothing to brag about.

Understanding how a computer stores its values (bits, bytes, etc) is a very important part of learning how to program the things. Using the wrong type can lead to all kinds of odd behaviour.
It also helps understanding why we always write

if (millis() - oldTime > interval) {
}

in this order and how it helps dealing with the millis() overflow.
No reason to try and hide stuff.

wvmarle:
Understanding how a computer stores its values (bits, bytes, etc) is a very important part of learning how to program the things. Using the wrong type can lead to all kinds of odd behaviour.
It also helps understanding why we always write

if (millis() - oldTime > interval) {

}



in this order and how it helps dealing with the millis() overflow.
No reason to try and hide stuff.

what does this have to do with the code that the OP is asking about? Seriously, name one way in which this relates to the question asked in the OP...

I DON'T NEED ANY LESSONS ON VARIABLE TYPES! I KNOW HOW THEY WORK! Instead of trying to educate me on something I obviously already know, why don't you try to help the poor guy who actually asked for help. Or at least start another thread to talk about this unrelated stuff.

Doesn't that sound like a better use of your time?

Look, I'm sorry I tried to talk to the OP in terms I thought he would understand. Apparently there are a few of you who just can't stand that. But what good are you doing here with all these post about me when you could be helping someone who needs it. From now on I promise I will try to keep it over the OP's head since that is what you guys seem to love more than anything.