Hello, I am new into Arduino universe, and I have a project, which I proceed to explain:
I need to cool objects fot 5 minutes. no one knows when will I put an object in the cooler nor which cooler I will use. Once the object is in the cooler, its led turns ON, then waits 5 minutes and starts blinking, indicating that I can pull out the object. when I remove the object the LED will turn OFF (reset)
--3 or more timers, with their respective start buttons.
--Once a button is pressed and hold, its timer turns on a LED, then counts (i.e.) 5 minutes.
--The LED starts blinking when the time is => 5 min (or whatever time set, the same for all the timers)
-- The count starts when the user puts something on the swith, of course all switches start at random times and orders, but all of them count the same time (ie 5 min) and then the LED start blinking.
Any Ideas? the Delay is not good idea... I am studing Millis but I am not sure how to make it work... sorry about my ignorance but there is only one millis... or isn´t?
I would like to paste my last try... but it definitely did not work... As I said, this is my first project.
The idea with millis() is to record the time when a button is pressed (1 variable per button - you want to use an unsigned long), and then each pass through loop, check if enough time has passed (between the time you recorded in that variable, and current time from millis) to do something.
Google will return thousands of examples... but an easy way for newbie would be a well documented library. Chrono (originally Metro) is one of those libraries.
Don't bother with a library - it's probably harder to learn how to use the library than how to use the timer directly, it's really that simple. Record the millis() value when the button is pressed, and as long as it's less than 5 minutes ago switch on the respective LED.
That should do the job. Very simple. Every button press starts the 5-minute timer; it will restart the counting if you press again halfway. If you don't want that, check for the button in the else block of the second if statement. Set buttonTime to -5 * 60 * 5000 to prevent the LEDs from switching on right away (why? Think about it).
In setup, set the pins to output/input_pullup as needed (another for loop).
Expand to as many pins you have.
Code untested, may have typos.