New Reef Angel is Awesome

New members questions
Post Reply
VSpeck
Posts: 13
Joined: Thu Dec 20, 2012 12:35 am

New Reef Angel is Awesome

Post by VSpeck »

I received my reef angel last week and I have started messing with coding some the last couple of days. I read a C++ tutorial but have no prior programming experience. Most of the code came from the forums but the tutorial helped to understand it. Thanks everyone for all the help you have provided without even talking to me yet :lol:

Anyway what i would like is somebody experienced to review my code. I have it controlling the tunzes for now since I cant really mess anything up in the tank with that but I'm scared to put everything on the controller until I have somebody look it over.

I want tunze control with a night mode which seems to be working
I want alk to dose on the hour between 11pm and 3pm the next day for ~1 minute
I dont know how big of a span I should give my heater does this look ok?

Ports are:

1 Heater
2 Cal Doser
3 Alk Doser
4 Return Pump
5 Right Tunze
6 Left Tunze
7 Actinic Leds
8 Mhs


Heres the code I'm using:

Code: Select all

#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 <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.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 | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port4Bit | Port6Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port7Bit | Port8Bit;
    // Ports turned off when Overheat temperature exceeded

    ReefAngel.OverheatShutoffPorts = Port1Bit | Port6Bit | Port8Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 841 );


    // Ports that are always on
    ReefAngel.Relay.On( Port4 );
    ReefAngel.Relay.On( Port5 );
    ReefAngel.Relay.On( Port6 );
    
}

    ////// Place additional initialization code below here
    

    ////// Place additional initialization code above here
 

     //Tunze short pulse functions
     byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
  byte tspeed=0;
  PulseMinSpeed=constrain(PulseMinSpeed,0,100);
  PulseMaxSpeed=constrain(PulseMaxSpeed,0,100);
  tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
  if (PulseSync)
    return tspeed;
  else
    return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}

    void loop()
{
    ReefAngel.StandardHeater( Port1,807,813 );
    ReefAngel.StandardLights( Port2,19,0,19,17 );
    ReefAngel.StandardLights( Port7,15,0,23,0 );
    ReefAngel.StandardLights( Port8,16,0,22,0 );

    
   //night mode for tunzes
    if ( (hour() >=23) || (hour() <=12) ) 
{
      ReefAngel.PWM.SetActinic( TunzeShortPulse(30,30,10,true) );
      ReefAngel.PWM.SetDaylight( TunzeShortPulse(30,50,5,false) );
}
    else
{
      //day mode for tunzes
    ReefAngel.PWM.SetActinic( TunzeShortPulse(30,50,2,true) ); 
    ReefAngel.PWM.SetDaylight( TunzeShortPulse(30,90,2,false) );
}

  //Night time alk dosing
   if ( ((hour() >= 23) || (hour() <= 15)) &&
       (minute() == 0) && 
       (second() <= 59) )
   {
      ReefAngel.Relay.On(Port3);
   }
   else 
   {
      ReefAngel.Relay.Off(Port3);
   }

    ////// Place your custom code below here
    

    ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.AddWifi();
    ReefAngel.ShowInterface();
}
Last edited by VSpeck on Thu Dec 20, 2012 9:57 am, edited 1 time in total.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: New Reef Angel is Awesome

Post by rimai »

Very good job :)
Looks pretty good.
The only thing I see is this line:

Code: Select all

ReefAngel.StandardLights( Port2,19,0,19,17 );
It tells port 2 to turn on at 7:00pm and turn off at 7:17pm
I don't know if this is intended or not, but would like to point out.
Roberto.
VSpeck
Posts: 13
Joined: Thu Dec 20, 2012 12:35 am

Re: New Reef Angel is Awesome

Post by VSpeck »

rimai wrote:Very good job :)
Looks pretty good.
The only thing I see is this line:

Code: Select all

ReefAngel.StandardLights( Port2,19,0,19,17 );
It tells port 2 to turn on at 7:00pm and turn off at 7:17pm
I don't know if this is intended or not, but would like to point out.
Thats what I intended. It is my calcium dosing pump and since it doesnt raise ph I am ok with dosing it all at once. Thanks for looking it over and thanks again for all the help.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

New Reef Angel is Awesome

Post by lnevo »

Ouch. You should not dose all at once as your calcium is gonna swing up and down. there are functions specific to dosing pumps that you can use instead of lights and you have a controller now so you can spread it out over multiple doses...
VSpeck
Posts: 13
Joined: Thu Dec 20, 2012 12:35 am

Re: New Reef Angel is Awesome

Post by VSpeck »

I had it on timers before and have always done it like this.

I had it originally programmed on dosing modes but I prefer it this way. I have talked to many people about it and as long as the calcium is there all day to be consumed it is not as critical that it stays as precise as temp or alk. This is jmho from what i have gathered and how I have run my reefs but thanks for the input.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

New Reef Angel is Awesome

Post by lnevo »

Thats fine. You can still use the dosing pump function. Or the lights if it suits you better :)
User avatar
DrewPalmer04
Posts: 818
Joined: Tue May 29, 2012 2:12 pm
Location: Christopher, IL

Re: New Reef Angel is Awesome

Post by DrewPalmer04 »

Welcome VSpeck
Out for now...but not over.

VISIT: Ethernet Module/Wifi Alternative
Post Reply