Reefology's code

Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Code: Select all

 // DC pumps
    // To run this code must choose Custom in portal
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { NutrientTransport, Sine, ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, LongPulse, Else, Gyre, NutrientTransport };

    if (now()%1200==0 || changeMode==true) { // Change every 20 (1200seconds) mins or controller reboot
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    
    if (now()-feeding<3000) {
    // Continue NutrientTranspot Mode for 45 minutes
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=NutrientTransport;
    } else if (now()%SECS_PER_DAY<37800 || now()%SECS_PER_DAY>=81000) { // 10:30am / 10:30pm
    // Night mode (go to 30%)
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Gyre;
    ReefAngel.DCPump.Speed=30;
    } else if (InternalMemory.DCPumpMode_read()==11) {
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }
hi, based on the code above, I don't understand why my pwm channels have been at 0 for the past 45 mins? can someone help me figure out what I've done wrong? thanks
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

What mode do you see in the screen?
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

not sure which screen you're referring to but in the portal, the internal memory keeps getting reset to 0's for both speed and duration? currently the mode alternates but it was set up in custom??
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

The RA screen. Move the joystick to the right or left.
Or are you using a custom screen?
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

it says normal mode. what is that? don't see it listed in the portal as a mode.
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

Normal?
Are you sure you are in the RF screen?
Can you send a picture?
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

sorry Roberto, the mode is gyre, duration is 15 and speed is 30
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

Which channels did you assign for DCPump?
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

lol, I just logged in to tell you i figured it out...had the actinic channel set to None and of course thought I had the pump wired to daylights :p

thanks Roberto
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Code: Select all

void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

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

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

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

void loop()
{
    ReefAngel.ActinicLights( Port1 );
    ReefAngel.DayLights( Port2 );
    ReefAngel.StandardHeater( Port3 );
    ReefAngel.StandardLights( Port5, 19,0,7,0);
    ReefAngel.DosingPumpRepeat1( Port6 );
    ReefAngel.DosingPumpRepeat2( Port7 );
    ReefAngel.DosingPumpRepeat3( Port8 );
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.DCPump.LowATOChannel = Sync; // WP40 
    ReefAngel.DCPump.HighATOChannel = AntiSync; // SW 8 
    ReefAngel.DCPump.AntiSyncOffset=125;
    
    ////// Place your custom code below here
    
    // DC pumps
    // To run this code must choose Custom in portal
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, LongPulse, Else, Gyre, NutrientTransport };

    if (now()%3600==0 || changeMode==true) { // Change every 60 mins (3600seconds) or controller reboot
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=NutrientTransport;
    ReefAngel.DCPump.Speed=80;
    // Night mode (go to 30%)
    } else if (now()%SECS_PER_DAY>25200 && now()%SECS_PER_DAY<=68400) { // 7am to 7pm
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Gyre;
    ReefAngel.DCPump.Speed=30;
    } else if (InternalMemory.DCPumpMode_read()==11) {
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }
Can someone here please tell me why my Jebao wavemaker pump is running full throttle constantly on the ATO high? the ATO low is working great. in fact I made an adaptor to run both pumps on my ATO low and they're working but I'd really like to get the antisync working. The code I'm using in the meantime is below.

thanks

Code: Select all


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

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

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

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

void loop()
{
    ReefAngel.ActinicLights( Port1 );
    ReefAngel.DayLights( Port2 );
    ReefAngel.StandardHeater( Port3 );
    ReefAngel.StandardLights( Port5 );
    ReefAngel.DosingPumpRepeat1( Port6 );
    ReefAngel.DosingPumpRepeat2( Port7 );
    ReefAngel.DosingPumpRepeat3( Port8 );
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.DCPump.LowATOChannel = Sync; // WP40 & SW 8
    ReefAngel.DCPump.HighATOChannel = None; //  
    
    ////// Place your custom code below here
    
    // DC pumps....................................
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, Else, Gyre, NutrientTransport };

    if (now()%1800==0 || changeMode==true)  // Change every 30 mins (1800seconds) or controller reboot
    {
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) 
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=ReefCrest;
    ReefAngel.DCPump.Speed=80;
    }
    
    // Night/Quiet mode
      else if (hour()>=2 && hour()<8 ) // 2am to 8am
    { 
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( Sine,35,10 );
    } 
      else if (hour()>=15 && hour()<19) // 3pm and 7pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( LongPulse,30,1 ); 
    }
    
    //Storm mode
    else if (hour()>=1 && hour()<2) // 1am and 2am
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( Else,80,15 );  
    }
      else if (hour()>=11 && hour()<12) // 11am and 12pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( LongPulse,95,2 );  
    }
    else if (hour()>=21 && hour()<22) // 9pm and 10pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( ReefCrest,85,15 );  
    }
    
    // Custom Mode and nothing else going on
    else if (InternalMemory.DCPumpMode_read()==11) 
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }
    ////// Place your custom code above here

Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Code: Select all



////// Place global variable code below here


////// Place global variable code above here


void setup()
{
    // This must be the first line
    InternalMemory.LCDID_write(255); //this line was added when i got a replacement RA+ board
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit | Port6Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port5Bit | Port6Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

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

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

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

void loop()
{
    ReefAngel.ActinicLights( Port1 );
    ReefAngel.DayLights( Port2 );
    ReefAngel.StandardHeater( Port3 );
    ReefAngel.Relay.DelayedOn(Port5 );
    ReefAngel.DosingPumpRepeat1( Port7 );
    ReefAngel.DosingPumpRepeat2( Port8 );
    ReefAngel.PWM.DaylightPWMSlope();
    ReefAngel.PWM.ActinicPWMSlope();
    ReefAngel.DCPump.LowATOChannel = Sync; // WP40 
    ReefAngel.DCPump.HighATOChannel = AntiSync; // SW-8
    ReefAngel.DCPump.AntiSyncOffset = 125;
    
    ////// Place your custom code below here
    
    // Wavemaker
    
    if ( ((hour() >= 2) && (hour() < 8)) || ((hour() >= 15) && (hour() < 19)) ) // off from 2am-8am & 3pm-7pm
      {
        ReefAngel.Relay.Off(Port6);
      }
        else
      {
        ReefAngel.WavemakerRandom( Port6, 30, 300 ); // random between 30 and 300 seconds
      }
  
  
    // DC pumps....................................
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, Else, Gyre, NutrientTransport };

    if (now()%1800==0 || changeMode==true)  // Change every 30 mins (1800seconds) or controller reboot
    {
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) 
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=ReefCrest;
    ReefAngel.DCPump.Speed=75;
    }
    
    // Night/Quiet mode
      else if (hour()>=2 && hour()<8 ) // 2am to 8am
    { 
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( Gyre,40,10 );
    } 
      else if (hour()>=15 && hour()<19) // 3pm and 7pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( ShortPulse,40,30 ); 
    }
    
    //Storm mode
    else if (hour()>=1 && hour()<2) // 1am and 2am
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( Else,70,15 );  
    }
      else if (hour()>=11 && hour()<12) // 11am and 12pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( ReefCrest,80,15 );  
    }
    else if (hour()>=21 && hour()<22) // 9pm and 10pm
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.SetMode( ShortPulse,85,30 );  
    }
    
    // Custom Mode and nothing else going on
    else if (InternalMemory.DCPumpMode_read()==11) 
    {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }
    ////// Place your custom code above here

Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Hoping someone can help with this. I'd like to add Seasonal changes to my code but can't get it to compile.

Code: Select all

void SeasonalTemps ()
 {
  static int heatArray[][2] = { {782,786},// default in case of error in month=0 (June)
                    {760,764},//January (winter)
                    {764,768},//February (winter)
                    {765,769},//March (early spring)
                    {769,773},//April (spring)
                    {775,779},//May (spring)
                    {782,786},//June (early summer)
                    {789,793},//July (summer)
                    {796,800},//August (summer)
                    {786,790},//September (early fall)
                    {777,781},//October (fall)
                    {770,774},//November (fall)
                    {765,769} };//December (early winter)
                    
               
  ReefAngel.StandardHeater( Port3,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps

where exactly do I input this?
Image
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Reefology's code

Post by binder »

you have to simply copy the entire function and paste it into your INO file, most likely at the end of it. well after the last curly brace of the loop.

Sent from my XT1585 using Tapatalk
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

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 <Humidity.h>
#include <DCPump.h>
#include <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here

void SeasonalTemps ()
 {
  static int heatArray[][2] = { {780,784},// default in case of error in month=0 (May)
                    {764,768},//January (winter)
                    {768,772},//February (winter)
                    {772,776},//March (early spring)
                    {776,780},//April (spring)
                    {780,784},//May (spring)
                    {784,788},//June (early summer)
                    {788,792},//July (summer)
                    {784,788},//August (summer)
                    {780,784},//September (early fall)
                    {776,780},//October (fall)
                    {772,776},//November (fall)
                    {768,772} };//December (early winter)
                   
               
  ReefAngel.StandardHeater( Port1,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port2Bit | Port4Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port3Bit | Port4Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

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

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

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

void loop()
{
    SeasonalTemps ();

    ReefAngel.ActinicLights( Port2 ); //ATS pump
    ReefAngel.DayLights( Port3 ); //ATS light
    ReefAngel.StandardLights( Port4, 23,0,7,0); //Skimmer 11pm-7am
    ReefAngel.DosingPumpRepeat1( Port6 );
    ReefAngel.DosingPumpRepeat2( Port7 );
    ReefAngel.DosingPumpRepeat3( Port8 );
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.DCPump.UseMemory = true;
    ReefAngel.DCPump.LowATOChannel = Sync; // SW 8 
    ReefAngel.DCPump.HighATOChannel = AntiSync; // SW 8 
    //ReefAngel.DCPump.AntiSyncOffset = 125; // % (0-255) of main pump (Sync)

    ////// Place your custom code below here
    
    // koralia 1150
    // if (hour()>=23 || hour()<11) ReefAngel.Relay.Off( Port5 );
    // else ReefAngel.WavemakerRandom( Port5, 120, 1800 );
    
    // DC pumps
    // To run this code must choose Custom in portal
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, LongPulse, Else, Gyre, NutrientTransport };

    if (now()%3600==0 || changeMode==true) { // Change every 60 mins (3600seconds) or controller reboot
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Else;
    ReefAngel.DCPump.Speed=80;
    // Night mode (go to 30%)
    } else if (now()%SECS_PER_DAY<39600 || now()%SECS_PER_DAY>=82800) { // 11pm to 11am
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Gyre;
    ReefAngel.DCPump.Speed=40;
    } else if (InternalMemory.DCPumpMode_read()==11) {
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }

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

    // This should always be the last line
   
}



Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Hoping someone from this great community can help as I'm not sure how to implement this. I'm looking to turn my kalk stirrer (port 7) off between 5pm and 11pm.

if ( hour(now()) >= 17 && hour(now()) <= 23 ) ReefAngel.Relay.Off( Port7 );

if the statement above is correct, where should I input it into my code?

Thanks
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

It has to be the line right after the kalkwasser function
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Hi Roberto,

so like this?


ReefAngel.DosingPumpRepeat1( Port6 );
ReefAngel.DosingPumpRepeat2( Port7 );
if ( hour(now()) >= 17 && hour(now()) <= 23 ) ReefAngel.Relay.Off(Port7 );
ReefAngel.DosingPumpRepeat3( Port8 );

Thanks
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

Yes. Looks good
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

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 <Humidity.h>
#include <DCPump.h>
#include <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here

void SeasonalTemps ()
 {
  static int heatArray[][2] = { {780,784},// default in case of error in month=0 (May)
                    {764,768},//January (winter)
                    {768,772},//February (winter)
                    {772,776},//March (early spring)
                    {776,780},//April (spring)
                    {780,784},//May (spring)
                    {784,788},//June (early summer)
                    {788,792},//July (summer)
                    {784,788},//August (summer)
                    {780,784},//September (early fall)
                    {776,780},//October (fall)
                    {772,776},//November (fall)
                    {768,772} };//December (early winter)
                   
               
  ReefAngel.StandardHeater( Port1,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port5Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port3Bit | Port4Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

    // Ports that are always on
    ReefAngel.Relay.On( Port2 );
    ReefAngel.Relay.On( Port5 );

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

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

void loop()
{
    SeasonalTemps();
  
    ReefAngel.ActinicLights( Port3 ); //Skimmer
    ReefAngel.DayLights( Port4 ); //ATS light
    ReefAngel.DosingPumpRepeat1( Port6 );
    ReefAngel.DosingPumpRepeat2( Port7 );
    if ( hour(now()) >= 17 && hour(now()) <= 23 ) ReefAngel.Relay.Off( Port7 ); //kalk dosing off 5pm-11pm
    ReefAngel.DosingPumpRepeat3( Port8 );
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.DCPump.UseMemory = true;
    ReefAngel.DCPump.LowATOChannel = Sync; // SW 8 
    ReefAngel.DCPump.HighATOChannel = AntiSync; // SW 8 
    //ReefAngel.DCPump.AntiSyncOffset = 125; // % (0-255) of main pump (Sync)

    ////// Place your custom code below here
    
    // koralia 1150
    // if (hour()>=23 || hour()<11) ReefAngel.Relay.Off( Port5 );
    // else ReefAngel.WavemakerRandom( Port5, 120, 1800 );
    
    // DC pumps
    // To run this code must choose Custom in portal
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, LongPulse, Else, Gyre, NutrientTransport };

    if (now()%3600==0 || changeMode==true) { // Change every 60 mins (3600seconds) or controller reboot
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Else;
    ReefAngel.DCPump.Speed=80;
    // Night mode (go to 30%)
    } else if (now()%SECS_PER_DAY<39600 || now()%SECS_PER_DAY>=82800) { // 11pm to 11am
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Gyre;
    ReefAngel.DCPump.Speed=40;
    } else if (InternalMemory.DCPumpMode_read()==11) {
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }

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

Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

hey Roberto, didnt work! any other ideas?
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

I tried the following in the custom code section instead and it worked:

// kalk reactor
if ( hour(now()) >= 17 && hour(now()) <= 23 ) ReefAngel.Relay.Off( Port7 ); //kalk dosing off 5pm-11pm
else ReefAngel.DosingPumpRepeat2( Port7 );
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

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 <Humidity.h>
#include <DCPump.h>
#include <PAR.h>
#include <ReefAngel.h>

////// Place global variable code below here

void SeasonalTemps ()
 {
  static int heatArray[][2] = { {780,784},// default in case of error in month=0 (May)
                    {764,768},//January (winter)
                    {768,772},//February (winter)
                    {772,776},//March (early spring)
                    {776,780},//April (spring)
                    {780,784},//May (spring)
                    {784,788},//June (early summer)
                    {788,792},//July (summer)
                    {784,788},//August (summer)
                    {780,784},//September (early fall)
                    {776,780},//October (fall)
                    {772,776},//November (fall)
                    {768,772} };//December (early winter)
                   
               
  ReefAngel.StandardHeater( Port1,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port5Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port5Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port3Bit | Port4Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    
  

    // Ports that are always on
    ReefAngel.Relay.On( Port2 );
    ReefAngel.Relay.On( Port5 );

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

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

void loop()
{
    SeasonalTemps();
  
    ReefAngel.ActinicLights( Port3 ); //Skimmer
    ReefAngel.DayLights( Port4 ); //ATS light
    ReefAngel.DosingPumpRepeat1( Port6 );
    //ReefAngel.DosingPumpRepeat2( Port7 );
    ReefAngel.DosingPumpRepeat3( Port8 );
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola();
    ReefAngel.DCPump.UseMemory = true;
    ReefAngel.DCPump.LowATOChannel = Sync; // SW 8 
    ReefAngel.DCPump.HighATOChannel = AntiSync; // SW 8 
    //ReefAngel.DCPump.AntiSyncOffset = 125; // % (0-255) of main pump (Sync)

    ////// Place your custom code below here
    
    // koralia 1150
    // if (hour()>=23 || hour()<11) ReefAngel.Relay.Off( Port5 );
    // else ReefAngel.WavemakerRandom( Port5, 120, 1800 );
    
    // kalk reactor
    if ( hour(now()) >= 17 && hour(now()) <= 23 ) ReefAngel.Relay.Off( Port7 ); //kalk dosing off 5pm-11pm
    else ReefAngel.DosingPumpRepeat2( Port7 );
    
    
    // DC pumps
    // To run this code must choose Custom in portal
    static int rmode;
    static boolean changeMode=true;

    // These are the modes we can cycle through. You can add more and even repeat...
    byte modes[] = { ReefCrest, Lagoon, TidalSwell, ShortPulse, Sine, LongPulse, Else, Gyre, NutrientTransport };

    if (now()%3600==0 || changeMode==true) { // Change every 60 mins (3600seconds) or controller reboot
    rmode=random(100)%sizeof(modes); // Change the mode by picking from our array
    changeMode=false;
    }

    // Set timer when in feeding mode
    static unsigned long feeding;
    if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();
    // Continue NutrientTranspot Mode for 30 minutes after feeding
    if (now()-feeding<1800) {
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Else;
    ReefAngel.DCPump.Speed=80;
    // Night mode (go to 30%)
    } else if (now()%SECS_PER_DAY<39600 || now()%SECS_PER_DAY>=82800) { // 11pm to 11am
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=Gyre;
    ReefAngel.DCPump.Speed=40;
    } else if (InternalMemory.DCPumpMode_read()==11) {
    // Custom Mode and nothing else going on
    ReefAngel.DCPump.UseMemory=false;
    ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
    ReefAngel.DCPump.Mode=modes[rmode]; // Put the mode to the random mode :)
    ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
    } else {
    ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
    }

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

Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

hey Roberto, wondering if this would work to turn off kalk reactor according to ph?

ReefAngel.PHControl( Port7 );

add this to the loop section and use it with the above code?

thanks
Image
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Reefology's code

Post by rimai »

Yes
Roberto.
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

note to self: add something like this for my fish room fan.

if (ReefAngel.Params.Temp[T3_PROBE] >= 825) ReefAngel.Relay.On(Port6);
if (ReefAngel.Params.Temp[T3_PROBE] <= 805) ReefAngel.Relay.Off(Port6);
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

My First RA* ino

Code: Select all


#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_TS.h>
#include <RA_TouchLCD.h>
#include <RA_TFT.h>
#include <RA_TS.h>
#include <Font.h>
#include <RA_Wifi.h>
#include <RA_Wiznet5100.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_ATO.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 <RA_CustomLabels.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <PAR.h>
#include <DCPump.h>
#include <ReefAngel.h>
#include <SoftwareSerial.h>

////// Place global variable code below here
void SeasonalTemps ()
 {
  static int heatArray[][2] = { {778,784},// default in case of error in month=0 (May)
                    {762,768},//January (winter)
                    {766,772},//February (winter)
                    {770,776},//March (early spring)
                    {774,780},//April (spring)
                    {778,784},//May (spring)
                    {782,788},//June (early summer)
                    {786,792},//July (summer)
                    {782,788},//August (summer)
                    {778,784},//September (early fall)
                    {772,780},//October (fall)
                    {770,776},//November (fall)
                    {766,772} };//December (early winter)
                   
               
  ReefAngel.StandardHeater( Box1_Port1,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Star();
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port2Bit;
    ReefAngel.FeedingModePortsE[1] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port2Bit;
    ReefAngel.WaterChangePortsE[1] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = 0;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port3Bit | Port4Bit | Port5Bit;
    ReefAngel.OverheatShutoffPortsE[1] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port3Bit;
    ReefAngel.LightsOnPortsE[1] = 0;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );
    
     // Ports that default on
   
    ReefAngel.Relay.On( Box1_Port8 );// Return
    
    
    ////// Place additional initialization code below here


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

void loop()
{
   SeasonalTemps();
    
    ReefAngel.ActinicLights( Box1_Port3 ); // Royal blue led strip
    ReefAngel.DayLights( Box1_Port4 ); // T5's
    ReefAngel.StandardLights( Box1_Port5,23,0,9,0 ); //Sump light
    ReefAngel.StandardFan( Box1_Port6 ); // Hood Fan
    ReefAngel.StandardLights( Box1_Port7 ); //Radions
    
    boolean buzzer=false;
    if ( buzzer ) ReefAngel.BuzzerOn(2); else ReefAngel.BuzzerOff();

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

 // Skimmer 
    if ((ReefAngel.HighATO.IsActive()) || (hour()>=9 && hour()<=19)) ReefAngel.Relay.Off( Box1_Port2); // Turns off when collection container is full or from 9am-7pm
    else ReefAngel.Relay.DelayedOn( Box1_Port2,5); //delay start 5 mins
    
    ////// Place your custom code above here

    ReefAngel.Network.Cloud();
    // This should always be the last line
    ReefAngel.ShowTouchInterface();
}


Tested for a day and have since added;

1. 2nd relay box (original RA+ box) via the relay expansion.
2. calcium reactor (formally controlled via smart bar)
3. Ozone (formally controlled via smart bar)
4. extra temp probes
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Last night I added this to shut down skimmer if return pump shuts down.

Code: Select all

// turn off skimmer if return pump is off 
    if (!ReefAngel.Relay.Status(Box1_Port8)) ReefAngel.Relay.Override(Box1_Port2,0); // Turn off skimmer 
I also define my relay ports by name, but have commented them out until I double check everything.

As well, trying to set up triggers using virtual relays, but am not having much luck. I tried this which reboots my RA*

Code: Select all

// Virtual relay to purge Co2 from calcium reactor
    if (ReefAngel.Relay.Status(Box3_Port1)) {
        // Turn off Co2 and recirculation pump
        ReefAngel.Relay.Off(Box2_Port2);
        ReefAngel.Relay.Off(Box2_Port3);

        // Delay for 2 minutes
        delay(120000); // 120000 milliseconds = 2 minutes

        // Turn on feed pump for 10 minutes
        ReefAngel.Relay.On(Box2_Port1);
        delay(600000); // 600000 milliseconds = 10 minutes

        // Turn off Box3_Port1
        ReefAngel.Relay.Off(Box3_Port1);
    }
Then I tried to simplify with this:

Code: Select all

// Virtual relay test
    if (ReefAngel.Relay.Status(Box3_Port8)) {
        // Turn on fan
        ReefAngel.Relay.On(Box1_Port6);

        // Delay for 2 minutes
        delay(30000); // 30000 milliseconds = 30 seconds

        // Turn off Virtual switch
        ReefAngel.Relay.Off(Box3_Port8);
    }
...same result.

According to the coding assistant in the webwizard, the delay function is the issue but not sure how to fix this?

If anyone has a work around, would love to hear it.
Image
User avatar
brennyn21
Posts: 114
Joined: Mon Nov 23, 2020 5:40 pm

Re: Reefology's code

Post by brennyn21 »

You typically don't want to use delays in codes as it will halt all other code below the delay statements. You can use the millis() instead to keep track of the time passed and execute lines bases on the time passed. Here is an example below

Place in global Variables

Code: Select all

enum State {
    IDLE,
    TURN_OFF_CO2_AND_PUMP,
    WAIT_TO_FEED_PUMP,
    TURN_ON_FEED_PUMP,
    WAIT_TO_TURN_OFF_FEED_PUMP,
    COMPLETE_CYCLE
};

State currentState = IDLE;  // Initial state
unsigned long lastUpdateTime = 0;  // Last update time
Place in Void Loop

Code: Select all

unsigned long currentMillis = millis();

    // Check if the condition to start the sequence is true
    if (ReefAngel.Relay.Status(Box3_Port1) && currentState == IDLE) {
        currentState = TURN_OFF_CO2_AND_PUMP;
    }

    switch (currentState) {
        case TURN_OFF_CO2_AND_PUMP:
            // Turn off CO2 and recirculation pump
            ReefAngel.Relay.Off(Box2_Port2);
            ReefAngel.Relay.Off(Box2_Port3);
            lastUpdateTime = currentMillis;  // Reset the timer
            currentState = WAIT_TO_FEED_PUMP;
            break;

        case WAIT_TO_FEED_PUMP:
            // Wait for 2 minutes before turning on the feed pump
            if (currentMillis - lastUpdateTime >= 120000) { // 120000 milliseconds = 2 minutes
                currentState = TURN_ON_FEED_PUMP;
            }
            break;

        case TURN_ON_FEED_PUMP:
            // Turn on the feed pump
            ReefAngel.Relay.On(Box2_Port1);
            lastUpdateTime = currentMillis;  // Reset the timer
            currentState = WAIT_TO_TURN_OFF_FEED_PUMP;
            break;

        case WAIT_TO_TURN_OFF_FEED_PUMP:
            // Wait for 10 minutes before turning off the feed pump
            if (currentMillis - lastUpdateTime >= 600000) { // 600000 milliseconds = 10 minutes
                currentState = COMPLETE_CYCLE;
            }
            break;

        case COMPLETE_CYCLE:
            // Turn off Box3_Port1
            ReefAngel.Relay.Off(Box3_Port1);
            currentState = IDLE;  // Reset the state to IDLE
            break;

        case IDLE:
            // Do nothing or handle other tasks
            break;
    }
Sincerely, Brennyn
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Thanks Brennyn, I'll give that a try later and let you know how it went.

I also tried the code below. And though it didn't reboot, it simply shut off the relays and nothing else

Code: Select all

  
   //Virtual relay to purge Co2 from calcium reactor
    unsigned long startTime = 0;
    unsigned long delayDuration = 0;
    int state = 0;


    // Check if co2purge is on
    if (ReefAngel.Relay.Status(co2purge)) {
        switch (state) {
            case 0:
                // Turn off Co2, feed pump and recirculation pump
                ReefAngel.Relay.Off(co2);
                ReefAngel.Relay.Off(cafeed);
                ReefAngel.Relay.Off(carecirc);
                startTime = millis();
                delayDuration = 60000; // 1 minute
                state = 1;
                break;
            case 1:
                // Check if 2 minutes delay has passed
                if (millis() - startTime >= delayDuration) {
                    // Turn on feed pump for 10 minutes
                    ReefAngel.Relay.On(cafeed);
                    startTime = millis();
                    delayDuration = 600000; // 10 minutes
                    state = 2;
                }
                break;
            case 2:
                // Check if 10 minutes delay has passed
                if (millis() - startTime >= delayDuration) {
                    // Turn off Box3_Port1
                    ReefAngel.Relay.Off(co2purge);
                    state = 0;
                }
                break;
        }
    }
Image
Reefology
Posts: 234
Joined: Fri Dec 26, 2014 6:38 pm

Re: Reefology's code

Post by Reefology »

Unfortunately nothing happens.

Heres the code I tried. Maybe you'll see something I don't. Thanks

Code: Select all


#include <Salinity.h>
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_TS.h>
#include <RA_TouchLCD.h>
#include <RA_TFT.h>
#include <RA_TS.h>
#include <Font.h>
#include <RA_Wifi.h>
#include <RA_Wiznet5100.h>
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_ATO.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 <RA_CustomLabels.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <Humidity.h>
#include <PAR.h>
#include <DCPump.h>
#include <ReefAngel.h>
#include <SoftwareSerial.h>


// Define Relay Ports by Name
#define heaters            Box1_Port1 
#define skimmer            Box1_Port2 
#define actinics           Box1_Port3 
#define t5                 Box1_Port4
#define sumplight          Box1_Port5
#define fan                Box1_Port6 
#define radions            Box1_Port7 
#define return             Box1_Port8 

#define cafeed             Box2_Port1 // CaRx Feed Pump
#define co2                Box2_Port2 // Co2 Solenoid
#define carecirc           Box2_Port3 // CaRx Recirculation Pump
#define dosing1            Box2_Port4
#define ozone              Box2_Port5
#define dosing2            Box2_Port6
#define powerheads         Box2_Port7
#define dosing3            Box2_Port8

// Virtual Relays
#define co2purge           Box3_Port1


////// Place global variable code below here

void SeasonalTemps ()
 {
  static int heatArray[][2] = { {778,784},// default in case of error in month=0 (May)
                    {762,768},//January (winter)
                    {766,772},//February (winter)
                    {770,776},//March (early spring)
                    {774,780},//April (spring)
                    {778,784},//May (spring)
                    {782,788},//June (early summer)
                    {786,792},//July (summer)
                    {782,788},//August (summer)
                    {778,784},//September (early fall)
                    {772,780},//October (fall)
                    {770,776},//November (fall)
                    {766,772} };//December (early winter)
                   
               
  ReefAngel.StandardHeater( heaters,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps
 
 //co2purge
 enum State {
    IDLE,
    TURN_OFF_CO2_AND_PUMPS,
    WAIT_TO_FEED_PUMP,
    TURN_ON_FEED_PUMP,
    WAIT_TO_TURN_OFF_FEED_PUMP,
    COMPLETE_CYCLE
};

State currentState = IDLE;  // Initial state
unsigned long lastUpdateTime = 0;  // Last update time

//end co2purge

////// Place global variable code above here


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    ReefAngel.Star();
    ReefAngel.AddExtraTempProbes(); // Adds 3 More Temp Probes
    ReefAngel.AddHumidityExpansion();  // Humidity Expansion 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port8Bit;
    ReefAngel.FeedingModePortsE[1] = Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port8Bit;
    ReefAngel.WaterChangePortsE[1] = Port7Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = 0;
    ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port3Bit | Port4Bit | Port7Bit;
    ReefAngel.OverheatShutoffPortsE[1] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    ReefAngel.LightsOnPortsE[0] = Port5Bit | Port7Bit;
    ReefAngel.LightsOnPortsE[1] = 0;
    // Use T2 probe as temperature and overheat functions
    ReefAngel.TempProbe = T2_PROBE;
    ReefAngel.OverheatProbe = T3_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );
    
    

    // Ports that default on
   
    ReefAngel.Relay.On( return );// Return
    ReefAngel.Relay.On( powerheads ); // DC power heads on smart bar
    
    // Ports that default off
    
    ReefAngel.Relay.Off( heaters ); // Heaters
    ReefAngel.Relay.Off( dosing1 ); // Dosing Pump 1
    ReefAngel.Relay.Off( dosing2 ); // Dosing Pump 2
    ReefAngel.Relay.Off( dosing3 ); // Dosing Pump 3
    
      //Virtual Relays
    ReefAngel.Relay.Off( co2purge );// Purge Co2 from Calcium Reactor
    ReefAngel.Relay.Off( Box3_Port2 );
    ReefAngel.Relay.Off( Box3_Port3 );
    ReefAngel.Relay.Off( Box3_Port4 );
    ReefAngel.Relay.Off( Box3_Port5 );
    ReefAngel.Relay.Off( Box3_Port6 );
    ReefAngel.Relay.Off( Box3_Port7 );
    ReefAngel.Relay.Off( Box3_Port8 );//Test Virtual Switch
    

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


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

void loop()
{
    SeasonalTemps();
    
    ReefAngel.ActinicLights( actinics ); // Royal blue led strip
    ReefAngel.DayLights( t5 ); // T5's
    ReefAngel.StandardLights( sumplight,23,0,9,0 ); //Sump light
    ReefAngel.StandardFan( fan ); // Hood Fan
    ReefAngel.StandardLights( radions,1,30,9,30 ); //Radions
    
    ReefAngel.StandardLights( co2,12,35,23,30 ); // Co2 Solenoid
    ReefAngel.StandardLights( carecirc,12,30,23,55 ); // CaRx Recirculation Pump
    ReefAngel.DosingPumpRepeat1( dosing1 );
    ReefAngel.DosingPumpRepeat( ozone,180,1440,1200 ); // Ozone, on 3am=180mins offset from midnight, 1440=every 1440 mins (once a day), for 20 mins=1200 sec's
    ReefAngel.DosingPumpRepeat2( dosing2 );
    ReefAngel.DosingPumpRepeat3( dosing3 );
    
    
    // Dimming Channels
    ReefAngel.PWM.DaylightPWMParabola();
    ReefAngel.PWM.ActinicPWMParabola(14,15,21,45,0,100,0);
    ReefAngel.PWM.Daylight2PWMParabola();
    ReefAngel.PWM.Actinic2PWMParabola();

    boolean buzzer=false;
    if ( buzzer ) ReefAngel.BuzzerOn(2); else ReefAngel.BuzzerOff();

    ////// Place your custom code below here
    
    // Turn off skimmer if return pump is off
    if (!ReefAngel.Relay.Status(return)) {
    ReefAngel.Relay.Override(skimmer, 0); // Turn off skimmer
    } else {
    ReefAngel.Relay.DelayedOn(skimmer,5); // Delay start skimmer when return pump is back on
}
    // Skimmer 
    if ((ReefAngel.HighATO.IsActive()) || (hour()>=9 && hour()<=18)) ReefAngel.Relay.Off( skimmer); // Turns off when collection container is full or from 9am-7pm
    else ReefAngel.Relay.DelayedOn( skimmer,5); //delay start 5 mins
    
     // CaRx Feed Pump
    if ((hour() == 6 && minute() <=10) || (hour()>=13 && hour()<23) || (hour() == 23 && minute() <50)) ReefAngel.Relay.On(cafeed);//On from 6-6:10am and 1-11:50pm
    else ReefAngel.Relay.Off(cafeed); 
    
    //start co2purge
    unsigned long currentMillis = millis();

    // Check if the condition to start the sequence is true
    if (ReefAngel.Relay.Status(co2purge) && currentState == IDLE) {
        currentState = TURN_OFF_CO2_AND_PUMPS;
    }

    switch (currentState) {
        case TURN_OFF_CO2_AND_PUMPS:
            // Turn off CO2 and Calcium Reactor pumps
            ReefAngel.Relay.Off(co2);
            ReefAngel.Relay.Off(carecirc);
            ReefAngel.Relay.Off(cafeed);
            lastUpdateTime = currentMillis;  // Reset the timer
            currentState = WAIT_TO_FEED_PUMP;
            break;

        case WAIT_TO_FEED_PUMP:
            // Wait for 1 minute before turning on the feed pump
            if (currentMillis - lastUpdateTime >= 60000) { // 60000 milliseconds = 1 minute
                currentState = TURN_ON_FEED_PUMP;
            }
            break;

        case TURN_ON_FEED_PUMP:
            // Turn on the feed pump
            ReefAngel.Relay.On(cafeed);
            lastUpdateTime = currentMillis;  // Reset the timer
            currentState = WAIT_TO_TURN_OFF_FEED_PUMP;
            break;

        case WAIT_TO_TURN_OFF_FEED_PUMP:
            // Wait for 10 minutes before turning off the feed pump
            if (currentMillis - lastUpdateTime >= 600000) { // 600000 milliseconds = 10 minutes
                currentState = COMPLETE_CYCLE;
            }
            break;

        case COMPLETE_CYCLE:
            // Turn off Box3_Port1
            ReefAngel.Relay.Off(co2purge);
            currentState = IDLE;  // Reset the state to IDLE
            break;

        case IDLE:
            // Do nothing or handle other tasks
            break;
    }
    //end co2purge
 
    //light mover
    //if (hour()>=9 && hour()<=21) ReefAngel.DosingPumpRepeat( Port6,0,90,2 );   //  from 9am - 9pm, with 0 minutes offset from midnight moves every 90 minutes 2 seconds 
    //else ReefAngel.Relay.Off( Port6);
    
   
   //carbon dosing
    //if (hour()>=6 && hour()<23) ReefAngel.DosingPumpRepeat1( Port8 );  
    //else ReefAngel.Relay.Off( Port8);

  //kalk dosing
    //if ((hour()>13 && hour()<20) || (ReefAngel.Params.PH > 845)) ReefAngel.Relay.Off( Port7); //  Kalk off 1pm - 8pm & if pH is > 8.45   
   // else ReefAngel.PHControl( Port7 );

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

    ReefAngel.Network.Cloud();
    // This should always be the last line
    ReefAngel.ShowTouchInterface();
}



// RA_STRING1=4rBCB5aEN369IDJFYl/ESQ==::NTdkYmJkMzM0ODdmMmE0NA==
// RA_STRING2=null
// RA_STRING3=null
// RA_LABEL LABEL_TEMP1=FishRoom
// RA_LABEL LABEL_TEMP2=Sump
// RA_LABEL LABEL_TEMP3=OverFlow
// RA_LABEL LABEL_TEMP4=LightCanopy
// RA_LABEL LABEL_TEMP5=Cabinet
// RA_LABEL LABEL_TEMP6=NotInUse
// RA_LABEL LABEL_DAYLIGHT=Daylight
// RA_LABEL LABEL_ACTINIC=Actinic
// RA_LABEL LABEL_ACTINIC2=Actinic 2
// RA_LABEL LABEL_DAYLIGHT2=Daylight 2
// RA_LABEL LABEL_PORT11=Heaters
// RA_LABEL LABEL_PORT12=Skimmer
// RA_LABEL LABEL_PORT13=Blue Leds
// RA_LABEL LABEL_PORT14=T5's
// RA_LABEL LABEL_PORT15=Sump Light
// RA_LABEL LABEL_PORT16=Fan
// RA_LABEL LABEL_PORT17=Radions
// RA_LABEL LABEL_PORT18=Return
// RA_LABEL LABEL_PORT21=Ca Feed
// RA_LABEL LABEL_PORT22=Co2 Sol
// RA_LABEL LABEL_PORT23=Ca Recir
// RA_LABEL LABEL_PORT24=Doser1
// RA_LABEL LABEL_PORT25=Ozone
// RA_LABEL LABEL_PORT26=Doser2
// RA_LABEL LABEL_PORT27=Power Heads
// RA_LABEL LABEL_PORT28=Doser3
// RA_LABEL LABEL_PORT31=Purge Co2
// RA_LABEL LABEL_PORT32=Virtual
// RA_LABEL LABEL_PORT33=Virtual
// RA_LABEL LABEL_PORT34=Virtual
// RA_LABEL LABEL_PORT35=Virtual
// RA_LABEL LABEL_PORT36=Virtual
// RA_LABEL LABEL_PORT37=Virtual
// RA_LABEL LABEL_PORT38=Test
//
Image
Post Reply