Custom code for cloud
Posted: Thu May 30, 2013 11:53 am
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
Community discussion about Reef Angel Controllers and reefing related subjects
https://forum.reefangel.com/
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()
{
}
Code: Select all
for (int i=0;i<6;i++)
ChannelValues[i]=60; // Just for initial values
Code: Select all
#define slope_duration 9 // duration of slope in secondscan 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.