Another way to do night mode and change speeds

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Another way to do night mode and change speeds

Post by lnevo »

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:

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));    
}
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.

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
     ) 
);
Normally it would look like this:

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));
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
)
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Another way to do night mode and change speeds

Post by rimai »

Pretty cool!! :ugeek:
Roberto.
Post Reply