Another way to do night mode and change speeds
Posted: Mon Jun 17, 2013 4:47 am
So I recently just helped someone with an if / else block that was basically just transitioning the speed from night mode and then bringing it up halfway for an hour and then finally the regular speed.
The original code looked something like this:
This whole if / else block could be re-written with one statement and utilize the PWMSlope command to transition from the night mode of 0% go to the starting 25% and over 60 minutes raise to the final daytime 50%
I've put it into multiple lines so you can see the arguments more clearly.
Normally it would look like this:
So what this does is just call your ReefAngel.PWM.SetDaylight with the same 2 arguments as before.
Except now, instead of static numbers for the 2 numeric arguments to ReefCrestMode, we've replaced them with the PWMSlope. Here are the arguments to PWMSlope. So what I did was say from 9am to 10pm we will go from 25% to 50% and it will take 60 minutes to get there. Otherwise we will use 0. So that last 0 is your last else. You could set it tthat last argument for whatever you want for your night mode to be.
Here's the definition for the PWMSlope command.
byte PWMSlope (
byte startHour,
byte startMinute,
byte endHour,
byte endMinute,
byte startPWM,
byte endPWM,
byte Duration,
byte oldValue
)
You could also do the same thing using the PWMParabola as well. The function is pretty much the same, just without the duration argument.
byte PWMParabola (
byte startHour,
byte startMinute,
byte endHour,
byte endMinute,
byte startPWM,
byte endPWM,
byte oldValue
)
The original code looked something like this:
Code: Select all
if (hour()>=10 && hour()<21)
{
ReefAngel.PWM.SetDaylight(ReefCrestMode(50,50,true));
}
else if (hour()>=9 && hour()<22)
{
ReefAngel.PWM.SetDaylight(ReefCrestMode(25,16,true));
}
else
{
ReefAngel.PWM.SetDaylight(ReefCrestMode(0,0,true));
}
I've put it into multiple lines so you can see the arguments more clearly.
Code: Select all
ReefAngel.PWM.SetDaylight(
ReefCrestMode(
PWMSlope(9,0,22,0,25,50,60,0),
PWMSlope (9,0,22,0,16,50,60,0),
true
)
);
Code: Select all
ReefAngel.PWM.SetDaylight(ReefCrestMode(PWMSlope(9,0,22,0,25,50,60,0),PWMSlope (9,0,22,0,16,50,60,0),true));
Except now, instead of static numbers for the 2 numeric arguments to ReefCrestMode, we've replaced them with the PWMSlope. Here are the arguments to PWMSlope. So what I did was say from 9am to 10pm we will go from 25% to 50% and it will take 60 minutes to get there. Otherwise we will use 0. So that last 0 is your last else. You could set it tthat last argument for whatever you want for your night mode to be.
Here's the definition for the PWMSlope command.
byte PWMSlope (
byte startHour,
byte startMinute,
byte endHour,
byte endMinute,
byte startPWM,
byte endPWM,
byte Duration,
byte oldValue
)
You could also do the same thing using the PWMParabola as well. The function is pretty much the same, just without the duration argument.
byte PWMParabola (
byte startHour,
byte startMinute,
byte endHour,
byte endMinute,
byte startPWM,
byte endPWM,
byte oldValue
)