![]() if we enter here it means that the 27 minutes have passed Here is the function that controls the clock In our cycle (loop), we insert among other actions, the Refill Control, what we do every now and then, when we look at the time waiting for 27 minutes: At any point in the sketch you can write Serial.println (millis (), obtaining a printout of the value on the terminal. sum 27 minutes to the current value of the clockĪs you may have guessed, writing millis () is equivalent to telling Arduino to look at his watch. Now in our setup we write the first value of the next refill We define another variable of the same type, where we will write from time to time, the time of the next refill of ink. Write it for convenience in a 32-bit variable (unsigned long), so we can easily change it: Let's calculate how many milliseconds there are in the 27 minutes that pass until the next tank refill: Its hands do not make a revolution every 12 hours, but being a 32-bit counter, incremented every millisecond (hence the name), after about 1193 hours it reaches its maximum value (4294967295), and then returns to zero and starts again. Just to complicate things, let's assume that Arduino is already doing other things, for example, interrogating a temperature sensor every 10 seconds and writing the value on a display.Īrduino has a watch inside, with slightly different characteristics from the one we wear on our wrist. Let's see how we could use Arduino to make the button press every 27 minutes. You just have to look at it every now and then. You continue like this, throughout the work shift, sure that the battery of your watch will continue to keep it running. ![]() A good idea is to mark the time of the next deadline on a piece of paper. You start assembling pens as fast as you can, but every now and then you look at your watch, and as soon as it is 8.30, or a few seconds later, you fill the tank with ink, and then you continue to assemble pens, not before you have calculated the next refill of ink, which will be at 8:57. Leave immediately, it is 8.03 am, the tank is full, so next refueling at 8.30 am. So try to be very precise, press it when the 27 minutes are up. If you do it too soon the tank pours, and you have to stop to clean the machine, if you do it too late, not enough refills come out, ready to whip up the pens quickly, and you have to slow down. The only point to pay attention to, this is the automatic machine that fills the ink refills: it does everything by itself, but every 27 minutes you have to fill the ink tank by pressing this button. The first day of work, the foreman gives you a brief explanation: here are the refills filled with ink, here the tubes (the body of the pen), and here the front caps and the rear caps Assembling a pen is simple, anyone can do it: insert the refill in the tube, put the rear cap and the front cap. The pay will be piecework, so the more pens produced, the more money you earn. Let's start with an example based on real life: imagine finding a job as a worker in a ballpoint pen factory, like the classic BIC. If so, do something that you want to do.Below is a simple explanation to understand the millis() function, which allows you to do non-blocking delays with the Arduino. ![]() First, you need to record the time at which the action took place then check continuously whether the required period has elapsed.
0 Comments
Leave a Reply. |