Hello guys, I am trying to make a project where specific LEDs turn on at a specific date. I am using Arduino Nano with RTC module DS1307.
I would like to ask you if there is a better and cleaner way than a bunch of else if statements like I use:
@anon73444976 I made 4x 2D arrays and a function that goes through the arrays, but there is another problem that arose... I call the function four times always with different arguments in loop(). How do I avoid calling the functions every second (it seems quite demanding even tho the arrays are size of [7][3]? I am using a blinking LED so when I add delay, the LED also stops blinking I would like to call the function every day or every two days because I am checking only day and month so I don't need to check every second
I would discard the DS1307 RTC module and use the DS3132. The latter has programmable alarms that could wake up your nano once a day for a single comparison, keeping the nano in deep sleep and ultra-low power the rest of the time.
You could have a variable called prevDay and use it like this:
static byte prevDay = 99;
...
if(tm.Day != prevDay){
//The day has changed, do stuff...
...
prevDay = tm.Day;
}
but as already pointed out, there is no point avoiding execution of complex code unless you are saving CPU% or battery power or whatever for something else to use.
int date = tm.Month * 100 + tm.Day;
switch (date)
{
case 619: // May 19th
case 705: // June 5th
breath(white);
break;
case 701: // June 1st
case 729: // June 29th
breath(yellow);
break;
case 711: // June 11th
case 725: // June 25th
breath(green);
break;
case 715: // June 15th
breath(blue);
break;
}