Page 1 of 5
Custom code, please help
Posted: Sat Apr 14, 2012 7:13 pm
by d0lph1n
Hello,
Please help me program the RA with the following features:
Port 1: LED (blue) dimmable
Port 2: LED (white) dimmable
Port 3: Skimmer
Port 4: Filter pump
Port 5: Fan/Chiller ( triggered by temp sensor 1 if temp > 79F)
Port 6: Fan LED (triggered by temp sensor 2 or 3 if temp > 120F or whatever is the optimum LED temp)
Port 7: Heater (temp on: 77.5F / temp off 78.5F)
Port 8: Dual ATO
Schedule (example)
6AM: Port1: on / dimmer1 value: minimum
7AM: Port1: on / dimmer1 value: 30%
9AM: Port 1 (last value), Port2: on / dimmer2 value minimum
12PM: Port 1 on / dimmer1 100% & Port2: on / dimmer2 100%
....
Menu
Menu1: Skimmer off (port3 timeout 1h)
Menu2: Filter pump off (port4 off timeout 1h)
Menu3: Maintenance (port 4 off, port 1&2 on, dimmer 1&2 100%, timeout until exit)
Menu4: Blue light (port1 on dimmer1 100%, port 2 off, timeout 1h)
Menu5: White light (port1 off, port 2 on dimmer2 100% timeout 1h)
Menu6: Moonlight (port1 on, dimmer1 min. value, port 2 off, timeout 1h)
Menu7: ATO & Overheat clear
Menu8: Date/time
Menu9: Exit
Other values
Ph7: 542
Ph10: 838
Hardware:
LED driver: 2 x Inventronics EUC -025S070DS - EUC Series 25 W 0.7 A 36 V Dimmable Outdoor Constant
Dimmer to RA: 2 xPWM-to-Analog
Thank you very much.
Re: Custom code, please help
Posted: Sat Apr 14, 2012 8:44 pm
by rimai
Try this:
Code: Select all
// Autogenerated file by RAGen (v1.2.2.171), (04/14/2012 20:36)
// RA_041412_2036.ino
//
// This version designed for v0.9.0 or later
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = 0;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = 0;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
////// Place additional initialization code below here
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
////// Place additional initialization code above here
}
void loop()
{
// Specific functions that use Internal Memory values
ReefAngel.StandardLights(Port1,6,0,18,0);
ReefAngel.StandardLights(Port2,9,0,15,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
////// Place your custom code below here
ReefAngel.PWM.SetActinic(PWMSlope(6,0,18,0,15,100,180,15));
ReefAngel.PWM.SetDaylight(PWMSlope(6,0,18,0,15,100,180,15));
if (ReefAngel.Params.Temp[T2_PROBE] > 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
////// Place your custom code above here
// This should always be the last line
ReefAngel.ShowInterface();
}
There is no menu yet, but it's a start so you can check if everything works fine.
One thing at a time
![Smile :)](./images/smilies/icon_e_smile.gif)
Re: Custom code, please help
Posted: Sun Apr 15, 2012 1:53 am
by d0lph1n
Thanks Roberto, I appreciate it. I'll test it 1st thing in the morning.
Re: Custom code, please help
Posted: Sun Apr 15, 2012 9:51 am
by d0lph1n
Roberto, please let me know how to wire the PWM-to-Analog to the driver's dimmer.
PWM-to-Analog has 2 wires and the dimmer has 3. Thank you.
I have found some info the in the driver's manual. Im connecting + to purple and - to green.
http://www.inventronics-co.com/uploads/ ... 10%20G.pdf
I understand most of the code except the line below. Where can I find more info?
ReefAngel.PWM.SetDaylight(PWMSlope(6,0,18,0,15,100,180,15));
Re: Custom code, please help
Posted: Sun Apr 15, 2012 11:43 am
by rimai
Re: Custom code, please help
Posted: Mon Apr 16, 2012 9:38 am
by d0lph1n
can I have multiple slopes per channel/per day? the slopes don't overlap.
Re: Custom code, please help
Posted: Mon Apr 16, 2012 10:11 am
by rimai
Yes.
You will need to create some logic, but here is the idea:
Code: Select all
if (hour()<12)
ReefAngel.PWM.SetDaylight(PWMSlope(6,0,11,0,15,100,180,15));
else
ReefAngel.PWM.SetDaylight(PWMSlope(14,0,18,0,15,100,180,15));
Re: Custom code, please help
Posted: Mon Apr 16, 2012 11:04 am
by d0lph1n
Perfect. Thanks.
if you remember, I mentioned on another post that I have 2 drivers and 4 circuits (2 xDaylight, 2xActinic) for this setup: 2 tanks and the lights of each tank run on opposite schedule.
Each driver powers just one circuit at any given hour as following:
Each driver is switched by a dpdt switch. Each switch is powered by a 120Ac to 5VDC source (port 1 & 2). The led drivers are plugin directly to the power outlet (not RA).
6AM: Port1&2 OFF: Driver 1 powers Actinic 1 & Driver 2 powers Actinic 2
RA will be simulating sunrise in Tank1 and sunset in Tank2
10AM: Port1 ON /Port 2 OFF
Driver 1 powers Actinic 1 & Driver2 powers Daylight1
RA will be simulating daytime in Tank1
(Tank2 total darkness)
6PM: Port1 off / Port 2 off
Port1&2 off: Driver 1 powers Actinic 1 & Driver 2 powers Actinic 2
RA will be simulating sunset in Tank1 and sunrise in Tank2
10PM: Port 1 ON / Port2 off
Port1&2 off: Driver 1 powers Daylight2 & Driver 2 powers Actinic 2
RA will be simulating daytime in Tank 2
(Tank1 total darkness)
For each segment of the day, i will setup a slope for each channel using the conditional logic or maybe is better to setup specific values for Daytime and Actinic.
What do you suggest?
Re: Custom code, please help
Posted: Mon Apr 16, 2012 6:06 pm
by d0lph1n
Please help, port6 is not engaged if the t2 or t3 > 1200
========
// Autogenerated file by RAGen (v1.2.2.171), (04/14/2012 20:36)
// RA_041412_2036.ino
//
// This version designed for v0.9.0 or later
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port3Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit | Port1Bit | Port2Bit | Port7Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
////// Place additional initialization code below here
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
////// Place additional initialization code above here
}
void loop()
{
// Specific functions that use Internal Memory values
ReefAngel.StandardLights(Port1,10,0,18,0);
ReefAngel.StandardLights(Port2,22,0,6,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
////// Place your custom code below here
if (hour()<22)
ReefAngel.PWM.SetDaylight(PWMSlope(6,0,22,0,0,70,240,0));
else
ReefAngel.PWM.SetDaylight(PWMSlope(22,1,5,59,0,70,240,0));
if (hour()<22)
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,70,240,0));
else
ReefAngel.PWM.SetActinic(PWMSlope(22,1,5,59,0,70,240,0));
if (ReefAngel.Params.Temp[T2_PROBE] > 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
if (ReefAngel.Params.Temp[T3_PROBE] > 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T3_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
////// Place your custom code above here
// This should always be the last line
ReefAngel.ShowInterface();
}
Re: Custom code, please help
Posted: Mon Apr 16, 2012 6:26 pm
by rimai
This code is just disregarding any check on T2.
What is exactly that you are trying to achieve?
T2 and T3 need to be above 120F or either one goes above?
Re: Custom code, please help
Posted: Mon Apr 16, 2012 6:32 pm
by d0lph1n
Either T2 or T3 should turn on port 6.
On port 6 I have the driver for 2 fans (1 fan per light). On each light I have a temp sensor.
Is this code better?
if (ReefAngel.Params.Temp[T2_PROBE] >= 1100 || ReefAngel.Params.Temp[T3_PROBE] >= 1100) ReefAngel.Relay.On(Port6);
else ReefAngel.Relay.Off(Port6);
Also, could you check my code for Slopes please. I'm afraid, after midnight, the IF slope will engage. Thank you very much.
This is the final code. Apologies, my only programming happend long long time ago on Commodore 64
Please let me know if the IF condition for PWSlopes is correct
// Autogenerated file by RAGen (v1.2.2.171), (04/14/2012 20:36)
// RA_041412_2036.ino
//
// This version designed for v0.9.0 or later
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port3Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port4Bit | Port1Bit | Port2Bit | Port7Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
////// Place additional initialization code below here
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
////// Place additional initialization code above here
}
void loop()
{
// Specific functions that use Internal Memory values
ReefAngel.StandardLights(Port1,10,0,19,0);
ReefAngel.StandardLights(Port2,22,0,6,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
////// Place your custom code below here
if (hour()<22 && hour()>6)
ReefAngel.PWM.SetDaylight(PWMSlope(6,0,18,0,0,70,240,0));
else
ReefAngel.PWM.SetDaylight(PWMSlope(22,1,5,59,0,70,240,0));
if (hour()<22 && hour()>6)
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,70,240,0));
else
ReefAngel.PWM.SetActinic(PWMSlope(22,1,5,59,0,70,240,0));
if (ReefAngel.Params.Temp[T2_PROBE] >= 1300 || ReefAngel.Params.Temp[T3_PROBE] >= 1300) ReefAngel.Relay.On(Port6);
else ReefAngel.Relay.Off(Port6);
////// Place your custom code above here
// This should always be the last line
ReefAngel.ShowInterface();
}
Re: Custom code, please help
Posted: Mon Apr 16, 2012 7:48 pm
by rimai
Try this:
Code: Select all
if (ReefAngel.Params.Temp[T2_PROBE] > 1200 || ReefAngel.Params.Temp[T3_PROBE] > 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T2_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
This way either on can turn the fan on and both have to be below 110 to turn it off.
Re: Custom code, please help
Posted: Tue Apr 17, 2012 9:42 am
by d0lph1n
Thanks again for your support. The temp sensor code has been working great. I'm very happy because during sunset/sunrise, the temps don't exceed 100F.
The PWMSlope code needed small adjustments but I'm getting very close to what I want.
Is it possible to lower the driver's output even more?
Re: Custom code, please help
Posted: Tue Apr 17, 2012 9:58 am
by rimai
Sorry
![Sad :(](./images/smilies/icon_e_sad.gif)
typo
Replace this:
Code: Select all
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T2_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
With this:
Code: Select all
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
Re: Custom code, please help
Posted: Tue Apr 17, 2012 10:00 am
by d0lph1n
No problem, I saw it when I posted it back on the forum
![Smile :)](./images/smilies/icon_e_smile.gif)
It's my fault for doing cut/paste without thinking.
One more question, is it possible to lower the LED driver's output even more?
Re: Custom code, please help
Posted: Tue Apr 17, 2012 10:14 am
by rimai
Which drivers are you using??
I've heard that Meanwells LPF series do all the way down to 3%.
My ELN series only go to about 15%.
I also heard that the new buckpucks and steve's led go really low too, but never used them. These require external power supply though.
I've also built my own driver at one point that could go to 1%... It's a pretty cool little driver. Only problem is that it heats soooo much
![Sad :(](./images/smilies/icon_e_sad.gif)
Re: Custom code, please help
Posted: Tue Apr 17, 2012 10:16 am
by d0lph1n
The driver is Inventronics EUC -025S070DS - EUC Series 25 W 0.7 A 36 V Dimmable Outdoor Constant
http://www.inventronics-co.com/uploads/ ... 10%20G.pdf
Re: Custom code, please help
Posted: Wed Apr 18, 2012 9:47 pm
by rimai
I never used those
Re: Custom code, please help
Posted: Sun Apr 22, 2012 3:55 pm
by d0lph1n
t2 & t3 show 185F and the overheat alarm is on. I have no idea why and what to do.
I tried reloading the memory & the main program again and again.
Please help.
P.S.: Now it displays error on t1,2,3
Re: Custom code, please help
Posted: Sun Apr 22, 2012 5:14 pm
by rimai
Let's try this:
1. Load this code:
Code: Select all
#include <OneWire.h>
/* DS18S20 Temperature chip i/o
*/
OneWire ds(8); // on pin 8
void setup(void) {
// initialize inputs/outputs
// start serial port
Serial.begin(57600);
}
void loop(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];
int Temp;
if ( !ds.search(addr)) {
delay(1000); // maybe 750ms is enough, maybe not
Serial.print("No more addresses.\n");
ds.reset_search();
return;
}
Serial.print("R="); //R=28 Not sure what this is
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
// if ( OneWire::crc8( addr, 7) != addr[7]) {
// Serial.print("CRC is not valid!\n");
// return;
// }
//28 DS18B20
//22 DS1822
//10 DS18S20
if ( addr[0] != 0x28) {
Serial.print("Device is not a DS18S20 family device.\n");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print("P=");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
// Serial.print(data[i], HEX);
// Serial.print(" ");
}
Temp=(data[1]<<8)+data[0];//take the two bytes from the response relating to temperature
//Temp=Temp>>4;//divide by 16 to get pure celcius readout
Temp=Temp/1.6;
Serial.print("T=");//output the temperature to serial port
Serial.print(Temp);
Serial.print("C ");
//next line is Fahrenheit conversion
Temp=Temp*1.8+320; // comment this line out to get celcius
Serial.print("T=");//output the temperature to serial port
Serial.print(Temp);
Serial.println("F ");
// Serial.print(" CRC=");
// Serial.print( OneWire::crc8( data, 8), HEX);
// Serial.println();
}
2. Open Serial Monitor on menu Tools->Serial Monitor
3. Change the baud rate to 57600 baud
4. Copy and past the results here
Re: Custom code, please help
Posted: Mon Apr 23, 2012 12:43 am
by d0lph1n
it looks like it was a weird contact issue. I was able to fix it by taping the t2&t3 cables to the ph connector.
Regarding PWMSlope, after midnight, it doesn't work anymore and the AP & DP are set to zero.
Please advise. Thank you.
if (hour() > 6 && hour() < 22)
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
else
ReefAngel.PWM.SetDaylight(PWMSlope(22,0,6,0,0,80,240,0));
if (hour() > 6 && hour() < 22)
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
else
ReefAngel.PWM.SetActinic(PWMSlope(22,0,6,0,0,80,180,0));
Re: Custom code, please help
Posted: Mon Apr 23, 2012 9:05 am
by rimai
The slope can't cross over to next day
![Sad :(](./images/smilies/icon_e_sad.gif)
What is that you are trying to achieve?
Re: Custom code, please help
Posted: Mon Apr 23, 2012 1:50 pm
by d0lph1n
I'm trying to have different settings between 10pm and 6am next day, for both drivers.
Re: Custom code, please help
Posted: Mon Apr 23, 2012 2:03 pm
by rimai
But, is the PWM supposed to be at 80% overnight?
Re: Custom code, please help
Posted: Mon Apr 23, 2012 2:43 pm
by d0lph1n
probably you don't remember, I have 2 drivers and 2 lights. Each light has A&D circuits. Practically, the drivers are shared by the lights ..on opposite schedule.
Re: Custom code, please help
Posted: Mon Apr 23, 2012 3:09 pm
by rimai
Ok, in this case, we will have to do some other logic.
Try this code and let me know if it works:
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 <ReefAngel.h>
void setup()
{
ReefAngel.Init();
}
void loop()
{
if (hour() > 6 && hour() < 22)
{
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
}
else
{
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,80,240,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,80,180,0));
}
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 8:34 am
by d0lph1n
Thanks Roberto. I'll test it tonight.
Re: Custom code, please help
Posted: Tue Apr 24, 2012 1:11 pm
by d0lph1n
I tested it and at midnight the ap/dp values go to zero. this is the code:
// Autogenerated file by RAGen (v1.2.2.171), (04/14/2012 20:36)
// RA_041412_2036.ino
//
// This version designed for v0.9.0 or later
/* The following features are enabled for this File:
#define VersionMenu
#define DisplayLEDPWM
#define wifi
#define WDT
#define SIMPLE_MENU
*/
#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 <ReefAngel.h>
////// Place global variable code below here
////// Place global variable code above here
void setup()
{
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port4Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port1Bit | Port2Bit | Port7Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = 0;
// Ports that are always on
ReefAngel.Relay.On(Port3);
ReefAngel.Relay.On(Port4);
////// Place additional initialization code below here
ReefAngel.PHMin=542;
ReefAngel.PHMax=838;
ReefAngel.TempProbe=T1_PROBE;
////// Place additional initialization code above here
}
void loop()
{
// Specific functions that use Internal Memory values
ReefAngel.StandardLights(Port1,10,0,19,0);
ReefAngel.StandardLights(Port2,22,0,6,0);
ReefAngel.StandardFan(Port5,787,793);
ReefAngel.StandardHeater(Port7,775,785);
ReefAngel.StandardATO(Port8,60);
////// Place your custom code below here
if (hour() > 6 && hour() < 22)
{
ReefAngel.PWM.SetDaylight(PWMSlope(10,0,18,0,0,80,180,0));
ReefAngel.PWM.SetActinic(PWMSlope(6,0,22,0,0,80,240,0));
}
else
{
ReefAngel.PWM.SetDaylight(PWMSlopeOvernight(22,0,6,0,0,80,240,0));
ReefAngel.PWM.SetActinic(PWMSlopeOvernight(22,0,6,0,0,80,180,0));
}
if (ReefAngel.Params.Temp[T2_PROBE] >= 1200 || ReefAngel.Params.Temp[T3_PROBE] >= 1200) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T2_PROBE] < 1100 && ReefAngel.Params.Temp[T3_PROBE] < 1100) ReefAngel.Relay.Off(Port6);
////// Place your custom code above here
// This should always be the last line
ReefAngel.ShowInterface();
}
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+NumMins(startHour, startMinute);
unsigned long StartD = Start + Duration;
unsigned long End = nextMidnight(now())+NumMins(endHour, endMinute);
unsigned long StopD = End - Duration;
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM, endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM, endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 1:59 pm
by rimai
I changed the function.
It should work now
Code: Select all
byte PWMSlopeOvernight(byte startHour, byte startMinute, byte endHour, byte
endMinute, byte startPWM, byte endPWM, byte Duration, byte oldValue)
{
unsigned long Start = previousMidnight(now())+((unsigned long)NumMins(startHour, startMinute)*60);
if (hour()<startHour) Start-=86400;
unsigned long StartD = Start + (Duration*60);
unsigned long End = nextMidnight(now())+((unsigned long)NumMins(endHour, endMinute)*60);
if (hour()<startHour) End-=86400;
unsigned long StopD = End - (Duration*60);
if ( now() >= Start && now() <= StartD )
return constrain(map(now(), Start, StartD, startPWM, endPWM),startPWM,
endPWM);
else if ( now() >= StopD && now() <= End )
{
byte v = constrain(map(now(), StopD, End, startPWM, endPWM),startPWM,
endPWM);
return endPWM-v+startPWM;
}
else if ( now() > StartD && now() < StopD )
return endPWM;
// lastly return the existing value
return oldValue;
}
Re: Custom code, please help
Posted: Tue Apr 24, 2012 2:22 pm
by d0lph1n
Binary sketch size: 32,378 bytes (of a 32,256 byte maximum)
processing.app.debug.RunnerException: Sketch too big;