Hello! I made a timer, and i want to count something until a timer display 00:00 (for ex: Counting number of pressing on a button, during 1 min). I know how to do these two tasks on by one, but not at the same time, because delays are the problem here. I searched solutions, and find the function 'millis()". I think it's exactly what i need, but i don't understand how does it work. Tell me your opinion, thanks to help me to build the program !
Tell me your opinion
My opinion is that there are plenty of examples around of doing two, or more, things at once, and that more examples are not needed.
My opinion is that you can exercise your google-fu and find them yourself.
My opinion is that using millis() to record when one event happened, and to determine how long ago that happened, is trivial enough that you shouldn't need examples.
Well, you did ask.
I think it's exactly what i need, but i don't understand how does it work.
Then read Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.
If you have any problems with the program that you write then post it here for help
Nick includes this before he gets down to coding with time
Let's look at an analogy. Say you want to cook breakfast. You need to cook:
Coffee - takes 1 minute
Bacon - takes 2 minutes
Eggs - takes 3 minutesNow a seasoned cook would NOT do this:
Put coffee on. Stare at watch until 1 minute has elapsed. Pour coffee.
Cook bacon. Stare at watch until 2 minutes have elapsed. Serve bacon.
Fry eggs. Stare at watch until 3 minutes have elapsed. Serve eggs.The flaw in this is that whichever way you do it, something is going to be cooked too early (and get cold).
In computer terminology this is blocking. That is, you don't do anything else until the one task at hand is over.
What you are likely to do is this:
Start frying eggs. Look at watch and note the time.
Glance at watch from time to time. When one minute is up then ...
Start cooking bacon. Look at watch and note the time.
Glance at watch from time to time. When another minute is up then ...
Put coffee on. Look at watch and note the time.
When 3 minutes are up, everything is cooked. Serve it all up.In computer terminology this is non-blocking. That is, keep doing other things while you wait for time to be up.
I like his explanations and he is thorough with the code.
I like his explanations
I do too. But, he's a lousy cook if he cooks bacon for twice as long as the coffee, and eggs for 50% longer than the bacon.
In my kitchen, using my equipment and techniques, the bacon takes the longest to cook.
But is your bacon Australian bacon? It might be thick as your finger from the belly of a tough old bush boar, or a drop bear.
BTW, I thought I was having a hard day but you must be having it worse.