Hello all,
I am seeking guidance on a sort of time-lapse project I have been working on. First off, I am a complete beginner with arduino, just as disclaimer.
My goal has been to make a simple device to control a set of grow lights for specific on/off intervals. The application is for time-lapse microscopy of cyanobacteria, which grow best under high light conditions.
General setup is with an arduino uno, small lcd display, and a power switch tail II. The program starts after a single button press.
My first prototype worked alright, I could get the lights on and off for different periods of time (1min off/ 14min on), but have been running into the issue that the timing on the arduino desynchronizes with the microscope control. Ie. the arduino isn't accurately measuring time. I've figured out that this is most likely because I have been relying on delay() to track seconds.
The basic structure of the code was:
-check for button press in void loop()
-when button is pressed, start the off interval, which is a separate function
-run the off interval for 1 minute using a while() loop,
- seconds counted for each loop with delay (1000)
- print a countdown timer to lcd
-when the off interval ends, start the on interval, another separate function - operates in the same manner as the off interval
I have been trying to use millis() instead of delay() to fix the problem and get accurately timed intervals, but am running into the problem that I can't reset the millis() timer at the start of each the interval functions. Since I ultimately need this to work over 30+ hours of timelapse, I need a robust but preferably simple solution.
I'm getting a bit lost with this. If anyone could offer some guidance or advice I'd be very appreciative!