Dimming Module code
-
- Posts: 13
- Joined: Thu Mar 20, 2014 7:13 pm
Dimming Module code
Searching for examples have not found much that nails this so looking for guidance.
So I am using my dimming module to drive external DC relays. I have managed to get them running with a simple on and off program using the saddle code programing with wizard using a delay of 0 seconds and picking a 5v on.
What I need to do now is configure a few of the outputs to
1) turn on and off at time increments like a wave maker
2) turn off in certain conditions like in feed mode or water change mode
3) turn off in alarm conditions like overheat
4) turn on or off with PH condition
So I am using my dimming module to drive external DC relays. I have managed to get them running with a simple on and off program using the saddle code programing with wizard using a delay of 0 seconds and picking a 5v on.
What I need to do now is configure a few of the outputs to
1) turn on and off at time increments like a wave maker
2) turn off in certain conditions like in feed mode or water change mode
3) turn off in alarm conditions like overheat
4) turn on or off with PH condition
Re: Dimming Module code
Several ways to do each one, but here are some examples:
0% to 100% every 5 seconds:
Turn off in feeding mode:
Turn off in wc mode:
Turn off on overheat
Turn on based on pH value:
0% to 100% every 5 seconds:
Code: Select all
if (now()%10<5)
ReefAngel.PWM.SetChannel(0,0);
else
ReefAngel.PWM.SetChannel(0,100);
Code: Select all
if (ReefAngel.DisplayedMenu==FEEDING_MODE) ReefAngel.PWM.SetChannel(0,0);
Code: Select all
if (ReefAngel.DisplayedMenu==WATERCHANGE_MODE) ReefAngel.PWM.SetChannel(0,0);
Code: Select all
if (bitRead(ReefAngel.AlerFlags,OverheatFlag)) ReefAngel.PWM.SetChannel(0,0);
Code: Select all
if (ReefAngel.Params.PH>800) ReefAngel.PWM.SetChannel(0,100);
Roberto.
-
- Posts: 13
- Joined: Thu Mar 20, 2014 7:13 pm
Re: Dimming Module code
Roberto,
so here is the code for my dimming module. Channel 3 is the port I am attempting to set up with a 12 second on/off 24hrs a day, and turn off during feed mode; it is a DC optioned channel not a PWM. I used your code in the apply custom code here and channel3 wont operate after upload.
this is what channel 3 looks like now before attempted change.
ReefAngel.PWM.SetChannel( 3, PWMSlope(0,0,0,0,60,60,0,60) );
ReefAngel.PWM.SetChannel( 4, PWMSlope(18,0,12,0,60,60,0,60) );
ReefAngel.PWM.SetChannel( 5, PWMSlope(8,0,20,0,60,60,0,60) );
this is where and how I input the new code.
////// Place your custom code below here
if (now()%10<12)
ReefAngel.PWM.SetChannel(3,0);
else
ReefAngel.PWM.SetChannel(3,100);
if (ReefAngel.DisplayedMenu==FEEDING_MODE) ReefAngel.PWM.SetChannel(3,0);
does it need set up as a slope and not simply a 100? I am also thinking is the code placed in the wrong location and if placed in the custom code section, should the old channel 3 info be deleted?
so here is the code for my dimming module. Channel 3 is the port I am attempting to set up with a 12 second on/off 24hrs a day, and turn off during feed mode; it is a DC optioned channel not a PWM. I used your code in the apply custom code here and channel3 wont operate after upload.
this is what channel 3 looks like now before attempted change.
ReefAngel.PWM.SetChannel( 3, PWMSlope(0,0,0,0,60,60,0,60) );
ReefAngel.PWM.SetChannel( 4, PWMSlope(18,0,12,0,60,60,0,60) );
ReefAngel.PWM.SetChannel( 5, PWMSlope(8,0,20,0,60,60,0,60) );
this is where and how I input the new code.
////// Place your custom code below here
if (now()%10<12)
ReefAngel.PWM.SetChannel(3,0);
else
ReefAngel.PWM.SetChannel(3,100);
if (ReefAngel.DisplayedMenu==FEEDING_MODE) ReefAngel.PWM.SetChannel(3,0);
does it need set up as a slope and not simply a 100? I am also thinking is the code placed in the wrong location and if placed in the custom code section, should the old channel 3 info be deleted?
Re: Dimming Module code
That's because the mathematical result of now()%10 is always going to be less than 12.
% is explained better in here:
http://arduino.cc/en/Reference/Modulo
So, if you want a full cycle (both on/off periods) to be 24 seconds, you need this:
% is explained better in here:
http://arduino.cc/en/Reference/Modulo
So, if you want a full cycle (both on/off periods) to be 24 seconds, you need this:
Code: Select all
if (now()%24<12)
Roberto.
Re: Dimming Module code
The best explanation of the syntax when we do examples with now() and % I have is this
now() % repeat_time < runtime
Note that now() is time in seconds...if you want minutes or hours or days multiply the time values by SECS_PER_MINUTE or whatever your interval is...
now() % repeat_time < runtime
Note that now() is time in seconds...if you want minutes or hours or days multiply the time values by SECS_PER_MINUTE or whatever your interval is...
-
- Posts: 13
- Joined: Thu Mar 20, 2014 7:13 pm
Re: Dimming Module code
thanks for the feedback Inevo & Roberto I appreciate it a lot!
-
- Posts: 13
- Joined: Thu Mar 20, 2014 7:13 pm
Re: Dimming Module code
For anyone else looking to do this and clarify one little thing.
if (now()%30<10)
ReefAngel.PWM.SetChannel(0,0);
else
ReefAngel.PWM.SetChannel(0,100);
The "runtime" is actually the first set channel command line before the else. so if the above lines are used the relay or channel is on for 20 seconds and off for 10 seconds.
I believe if you reversed the 0 & 100 it would reverse and be off for 20 seconds and on for 10. Not sure.
I placed the code in the put custom code here section, and removed the PWM.Set channel in the upper section where it has the PWM channels in series. Not sure if this matters but it is working as planned.
if (now()%30<10)
ReefAngel.PWM.SetChannel(0,0);
else
ReefAngel.PWM.SetChannel(0,100);
The "runtime" is actually the first set channel command line before the else. so if the above lines are used the relay or channel is on for 20 seconds and off for 10 seconds.
I believe if you reversed the 0 & 100 it would reverse and be off for 20 seconds and on for 10. Not sure.
I placed the code in the put custom code here section, and removed the PWM.Set channel in the upper section where it has the PWM channels in series. Not sure if this matters but it is working as planned.
Re: Dimming Module code
You could also switch the < to a > to change the behavior
Always a few ways to skin the cat... 

