Wanting to do a code overhall

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
Dctrojan
Posts: 96
Joined: Wed Oct 16, 2013 9:50 am

Wanting to do a code overhall

Post by Dctrojan »

Ok im wanting to update my current code with a improved code which accomplishes the following things:

-Turn wavemaker on nutrient transport mode after feeding is over for 4 hours.
-Turn DC pump off for 2 hours after entering feeding mode.
-I also want my protein skimmer to remain off for 4 hours after pressing the feeding button.

could anyone point me in the right direction with a example of that?
Im mostly confused on where do i place the custom code in my current code. Also could someone explain to me how do i get my code to show up in a scroll box in a post? I cant seem to figure it out. I press the CODE button and insert my code.
Thanks for all the help.
Summer_high_lights_slope.ino
Current code
(4 KiB) Downloaded 346 times

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 <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
    ReefAngel.Use2014Screen();  // Let's use 2014 Screen 
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port1Bit | Port2Bit | Port4Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port4Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port4Bit | Port5Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 829 );

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


    // Ports that are always on
    ReefAngel.Relay.On( Box1_Port1 );
    ReefAngel.Relay.On( Box1_Port2 );
    ReefAngel.Relay.On( Box1_Port3 );
    ReefAngel.Relay.On( Box1_Port5 );
    ReefAngel.Relay.On( Box1_Port7 );
    ReefAngel.Relay.On( Box1_Port8 );

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

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

void loop()
{
    ReefAngel.StandardLights( Port1,14,30,20,00 ); ////// White t5
    ReefAngel.StandardLights( Port2,13,00,22,00 ); ////// blue t5
    ReefAngel.StandardLights( Port3,12,00,23,00 ); ////// reefblok blue
    ReefAngel.StandardLights( Port4,14,00,21,00 ); ////// reefblok white
    ReefAngel.StandardLights( Port5,14,30,21,00 ); ////// custom led
    ReefAngel.StandardLights( Port6,14,0,23,0 ); ////// uv
    ReefAngel.StandardLights( Port7,22,0,13,0 ); ////// night light
    ReefAngel.StandardHeater( Port8,800,820 );
    ReefAngel.StandardLights ( Box1_Port4, 12,0,22,00 ); ////// protein skimmer
    ReefAngel.SingleATO( true,Box1_Port6,66,0 );
    ReefAngel.PWM.SetChannel( 0, PWMSlope(13,30,22,0,5,40,60,5) ); ////// whites
    ReefAngel.PWM.SetChannel( 1, PWMSlope(12,0,23,0,5,100,60,20) ); ////// blue reefblok
    ReefAngel.PWM.SetChannel( 2, PWMSlope(14,0,22,0,5,100,60,5) ); ////// blue
    ReefAngel.PWM.SetChannel( 3, MoonPhase() );
    ReefAngel.PWM.SetDaylight (62); ////// Dc pump
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( NutrientTransport,90,100 ); ////// wavemaker
    ReefAngel.DCPump.ActinicChannel = Sync;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    

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

    // This should always be the last line
    ReefAngel.Portal( "Dctrojan" );
    ReefAngel.ShowInterface();
}

rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wanting to do a code overhall

Post by rimai »

I think it is time for us to have a variable to hold the time of the last feeding. More and more people are trying to do that and it would make things easier to code.
I'll add to the github issues

Sent from my SM-G900P using Tapatalk
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wanting to do a code overhall

Post by rimai »

Try this:

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 <ReefAngel.h>

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

time_t StartFeeding=0;
time_t StopFeeding=0;
boolean Feeding=false;

////// 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 
    ReefAngel.AddPHExpansion();  // pH Expansion Module
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = 0;
    ReefAngel.FeedingModePortsE[0] = Port1Bit | Port2Bit | Port4Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port4Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port1Bit | Port2Bit | Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port4Bit | Port5Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 829 );

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


    // Ports that are always on
    ReefAngel.Relay.On( Box1_Port1 );
    ReefAngel.Relay.On( Box1_Port2 );
    ReefAngel.Relay.On( Box1_Port3 );
    ReefAngel.Relay.On( Box1_Port5 );
    ReefAngel.Relay.On( Box1_Port7 );
    ReefAngel.Relay.On( Box1_Port8 );

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

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

void loop()
{
    ReefAngel.StandardLights( Port1,14,30,20,00 ); ////// White t5
    ReefAngel.StandardLights( Port2,13,00,22,00 ); ////// blue t5
    ReefAngel.StandardLights( Port3,12,00,23,00 ); ////// reefblok blue
    ReefAngel.StandardLights( Port4,14,00,21,00 ); ////// reefblok white
    ReefAngel.StandardLights( Port5,14,30,21,00 ); ////// custom led
    ReefAngel.StandardLights( Port6,14,0,23,0 ); ////// uv
    ReefAngel.StandardLights( Port7,22,0,13,0 ); ////// night light
    ReefAngel.StandardHeater( Port8,800,820 );
    ReefAngel.StandardLights ( Box1_Port4, 12,0,22,00 ); ////// protein skimmer
    ReefAngel.SingleATO( true,Box1_Port6,66,0 );
    ReefAngel.PWM.SetChannel( 0, PWMSlope(13,30,22,0,5,40,60,5) ); ////// whites
    ReefAngel.PWM.SetChannel( 1, PWMSlope(12,0,23,0,5,100,60,20) ); ////// blue reefblok
    ReefAngel.PWM.SetChannel( 2, PWMSlope(14,0,22,0,5,100,60,5) ); ////// blue
    ReefAngel.PWM.SetChannel( 3, MoonPhase() );
    ReefAngel.PWM.SetDaylight (62); ////// Dc pump
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( NutrientTransport,90,100 ); ////// wavemaker
    ReefAngel.DCPump.ActinicChannel = Sync;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
    
    if (!Feeding && ReefAngel.DisplayedMenu==FEEDING_MODE)
    {
      Feeding=true;
      StartFeeding=now();
    }
    if (Feeding && ReefAngel.DisplayedMenu!=FEEDING_MODE)
    {
      Feeding=false;
      StopFeeding=now();
    }
    if (now()-StopFeeding < 4*SECS_PER_HOUR)
    {
      // NTM for 4 hours after feeding
      ReefAngel.DCPump.SetMode( NutrientTransport,90,100 ); ////// wavemaker
    }
    if (now()-StartFeeding < 2*SECS_PER_HOUR)
    {
      // Turn DC Pump off
      ReefAngel.PWM.SetDaylight (0); ////// Dc pump
    }
    
    if (now()-StartFeeding < 4*SECS_PER_HOUR)
    {
      // Turn Skimmer off
      ReefAngel.Relay.Off(Box1_Port4);
    }

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

    // This should always be the last line
    ReefAngel.Portal( "Dctrojan" );
    ReefAngel.ShowInterface();
}

Roberto.
User avatar
Dctrojan
Posts: 96
Joined: Wed Oct 16, 2013 9:50 am

Re: Wanting to do a code overhall

Post by Dctrojan »

Thanks so much for taking a look at my code. I'll try it out later on today.
User avatar
Dctrojan
Posts: 96
Joined: Wed Oct 16, 2013 9:50 am

Re: Wanting to do a code overhall

Post by Dctrojan »

okay after trying the code it works great. i plan on tweaking it slightly . but now for some reason my reefblok blue leds aren't working. i've narrowed it down to either a bad connection on a driver wire or the programming to the driver. i know the power to the led isn't the problem. is there anywhere in the code that the pwm set channel 1 is canceled?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Wanting to do a code overhall

Post by rimai »

No. Nothing has been changed on that.

Sent from my SM-G900P using Tapatalk
Roberto.
Post Reply