Custom code for cloud
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Custom code for cloud
Looking for a code to make a cloud pass over tank. Left white LEDs port 0 blues port 1 middle whites port2 blues port3 right white LEDs port4 blues port5
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Custom code for cloud
How do you envision this working for you?
Going left to right?
Does it go all off before it comes back on? Or left starts to ramp up again before right goes dark?
Going left to right?
Does it go all off before it comes back on? Or left starts to ramp up again before right goes dark?
Roberto.
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
Either left or right doesn't make a difference to me. I was thinking say left one ramps down to 15 at a fast pace then once its close to low end the middle starts to go down to same 15 same speed and repeat for right LEDs let stay dim for a min. Or 2 then left ramps back up and goes across like it did for dimming. Another thing I'm not sure if it matters but I run my blues at 40 and whites at 35 peak power.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Custom code for cloud
Try this:
This test code will create a cloud every 5 minutes, that lasts for about 2 minutes.
Code: Select all
#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>
#define slope_duration 9 // duration of slope in seconds
#define cloud_duration 120 // duration of cloud in seconds
#define cloud_percentage 15 // percentage for the dimming channel when the cloud is passing
unsigned long dim_millis;
boolean start_cloud=false;
int ChannelValues[]={
0,0,0,0,0,0};
void setup()
{
ReefAngel.Init();
}
void loop()
{
for (int i=0;i<6;i++)
ChannelValues[i]=60; // Just for initial values
if (now()%300==0) start_cloud=true;
if (start_cloud) // Cloud trigger was fired. Starting cloud
{
dim_millis=millis();
start_cloud=false;
}
// Cloud started
// Ramping down
if (millis()-dim_millis<slope_duration*1000)
{
byte OriginalChannelValues[]={
0,0,0,0,0,0 };
for (int i=0;i<6;i++)
OriginalChannelValues[i]=ChannelValues[i];
ChannelValues[0]=map(millis()-dim_millis,0,slope_duration/3*1000,OriginalChannelValues[0],cloud_percentage);
ChannelValues[1]=map(millis()-dim_millis,0,slope_duration/3*1000,OriginalChannelValues[1],cloud_percentage);
ChannelValues[2]=map(millis()-dim_millis,slope_duration/3*1000,slope_duration*2/3*1000,OriginalChannelValues[2],cloud_percentage);
ChannelValues[3]=map(millis()-dim_millis,slope_duration/3*1000,slope_duration*2/3*1000,OriginalChannelValues[3],cloud_percentage);
ChannelValues[4]=map(millis()-dim_millis,slope_duration*2/3*1000,slope_duration*1000,OriginalChannelValues[4],cloud_percentage);
ChannelValues[5]=map(millis()-dim_millis,slope_duration*2/3*1000,slope_duration*1000,OriginalChannelValues[5],cloud_percentage);
for (int i=0;i<6;i++)
{
if (ChannelValues[i]<0) ChannelValues[i]=0;
ChannelValues[i]=constrain(ChannelValues[i], cloud_percentage, OriginalChannelValues[i]);
}
}
// Full Cloud
// Stay at defined cloud_percentage
if (millis()-dim_millis>slope_duration*1000 && millis()-dim_millis<(slope_duration+cloud_duration)*1000 )
{
for (int i=0;i<6;i++)
ChannelValues[i]=cloud_percentage;
}
// Cloud is ending
// Ramping up
if (millis()-dim_millis>(slope_duration+cloud_duration)*1000 && millis()-dim_millis<(slope_duration+slope_duration+cloud_duration)*1000 )
{
byte OriginalChannelValues[]={
0,0,0,0,0,0 };
for (int i=0;i<6;i++)
OriginalChannelValues[i]=ChannelValues[i];
ChannelValues[0]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),0,slope_duration/3*1000,cloud_percentage,OriginalChannelValues[0]);
ChannelValues[1]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),0,slope_duration/3*1000,cloud_percentage,OriginalChannelValues[1]);
ChannelValues[2]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),slope_duration/3*1000,slope_duration*2/3*1000,cloud_percentage,OriginalChannelValues[2]);
ChannelValues[3]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),slope_duration/3*1000,slope_duration*2/3*1000,cloud_percentage,OriginalChannelValues[3]);
ChannelValues[4]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),slope_duration*2/3*1000,slope_duration*1000,cloud_percentage,OriginalChannelValues[4]);
ChannelValues[5]=map(millis()-dim_millis-((slope_duration+cloud_duration)*1000),slope_duration*2/3*1000,slope_duration*1000,cloud_percentage,OriginalChannelValues[5]);
for (int i=0;i<6;i++)
{
if (ChannelValues[i]<0) ChannelValues[i]=0;
ChannelValues[i]=constrain(ChannelValues[i], cloud_percentage, OriginalChannelValues[i]);
}
}
for (int i=0;i<6;i++)
ReefAngel.PWM.SetChannel(i,ChannelValues[i]);
ReefAngel.ShowInterface();
}
byte x,y;
char text[10];
void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.Clear(BtnActiveColor,5,0,127,11);
ReefAngel.LCD.DrawText(DefaultBGColor,BtnActiveColor,30,3,"My Reef Angel");
ReefAngel.LCD.DrawDate(6, 122);
pingSerial();
ReefAngel.LCD.DrawMonitor(15, 20, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue());
pingSerial();
ReefAngel.LCD.Clear(DefaultFGColor,5,52,127,52);
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,30,55,"PWM Expansion");
x=15;
y=68;
for (int a=0;a<6;a++)
{
if (a>2) x=75;
if (a==3) y=68;
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a);
ConvertNumToString(text, ReefAngel.PWM.GetChannelValue(a), 1);
strcat(text," ");
ReefAngel.LCD.DrawText(COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,text);
y+=10;
}
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 103, TempRelay);
}
void DrawCustomGraph()
{
}
Roberto.
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
Got it loaded. Right away it dimmed down to 15 from left to right pretty quickly. Stayed dim thin it all turned on really bright like 60% then I think it dimmed right back down to 15 so its almost like its backwards other then how it jumped all lights up to 60. Blues should be 35% whites 40%
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Custom code for cloud
Have you tested?? Does it work?
The 60% was hard coded as just the example.
It's this part of the code:
I left a few comments through the code for you to kind of follow what the code is doing.
If it works, you can merge into your own code.
The 60% was hard coded as just the example.
It's this part of the code:
Code: Select all
for (int i=0;i<6;i++)
ChannelValues[i]=60; // Just for initial values
If it works, you can merge into your own code.
Roberto.
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
It dimmed down fine but it didn't ramp back up it just flashed instantly back up. Also can I slow it down some so it don't move in quit so fast?
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Custom code for cloud
Yeah, just change the duration of the ramp.
Code: Select all
#define slope_duration 9 // duration of slope in secondsRoberto.
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
ok cool how about the ramping back up part? it doesnt ramp up it just goes from 15 to 60 i looked through the code but not real sure what im looking at, where is the ramp up rate? also when it does work correctly what part of this code do i use or do i use the entire code?
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
can you set two different values? channels 0,2,4 at 40 and channels 1,3,5 at 35?rimai wrote:Have you tested?? Does it work?
The 60% was hard coded as just the example.
It's this part of the code:I left a few comments through the code for you to kind of follow what the code is doing.Code: Select all
for (int i=0;i<6;i++) ChannelValues[i]=60; // Just for initial values
If it works, you can merge into your own code.
-
rimai
- Posts: 12857
- Joined: Fri Mar 18, 2011 6:47 pm
Re: Custom code for cloud
I still didn't have time to test the ramp up.
What are you using for your code to set those %s right now?
What are you using for your code to set those %s right now?
Roberto.
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
-
jjdezek
- Posts: 327
- Joined: Fri May 17, 2013 1:35 pm
Re: Custom code for cloud
dont need this code anymore since i loaded the weather lighting code into the dimmer expansion module. thanks for the help.