Manipulating time variables
Posted: Tue May 05, 2015 8:35 am
I would like to make use of the internal memory variables for storing standard light times, and then calculate offsets from those times for different lighting channels (e.g., red channels start earlier and end later, to simulate warm light at sunrise/sunset).
I'm not sure how best to calculate offsets against the minutes, however, as the internal memory stores the hours and minutes separately, and an offset that would take the minutes higher than 60 or lower than 0 would probably cause a problem.
If I were using a PWM code to calculate the light level for a given time, how could I modify this to calculate the correct hour and minute values if I want to offset it by 30 minutes, and don't know whether that will take me past an hour threshhold?
Is there a function somewhere that can accommodate this, or can someone help me with some custom code to take the existing hour and minute variables and calculate a new variable based on the offset?
something like
If the Offset is a byte, and therefore limited to 255, I figure I cant wind up adding more than five hours, so I iterate that check of exceeding 60 five times.
This doesn't seem terribly efficient, and would require another function to accommodate offsets going the other way, and potentially another to handle offsets that push the hour past midnight.
I'm not sure how best to calculate offsets against the minutes, however, as the internal memory stores the hours and minutes separately, and an offset that would take the minutes higher than 60 or lower than 0 would probably cause a problem.
If I were using a PWM code to calculate the light level for a given time, how could I modify this to calculate the correct hour and minute values if I want to offset it by 30 minutes, and don't know whether that will take me past an hour threshhold?
Code: Select all
PWMSmoothRampHighRes(InternalMemory.StdLightsOnHour_read(), InternalMemory.StdLightsOnMinute_read(), InternalMemory.StdLightsOffHour_read(), InternalMemory.StdLightsOffMinute_read(), 0, 100, 120, 0);
Is there a function somewhere that can accommodate this, or can someone help me with some custom code to take the existing hour and minute variables and calculate a new variable based on the offset?
something like
Code: Select all
if (InternalMemory.StdLightsOnMinute_read()+Offset>60)
{
byte newMinutes=InternalMemory.StdLightsOnMinute_read()-60;
byte newHour=InternalMemory.StdLightsOnHour_read()+1
for (int a=0;a<5;a++) {
if newMinutes > 60 (newMinutes=newMinutes-60; newHour=newHour+1;)
};
};
This doesn't seem terribly efficient, and would require another function to accommodate offsets going the other way, and potentially another to handle offsets that push the hour past midnight.