Coding Moonlights

Do you have a question on how to do something.
Ask in here.
Post Reply
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Coding Moonlights

Post by ecam »

Can someone, help me code the following.

I have a stunner strip that Im using as my moonlights. I know want to you it to simulate sunrise and sunset as well.

Essentially I want to do the following:

from 6am to 10am ramp up from 10 to 100... turn off

from 8 pm to 11 am turn on.... and ramp down from 100 to 10.

Any help would be greatly appreciated

i currently run this:

Code: Select all

           ReefAngel.Relay.Off( Box1_Port3); // Start with the relay off       Port #11 Moonlight
                  if (hour()>=5 && hour()<10) ReefAngel.Relay.On(Box1_Port3); // Moonlight Between 5-10am turn the relay on
                  if (hour()>=20 && hour()<=23) ReefAngel.Relay.On(Box1_Port3); // From 8pm-Midnight turn the relay on
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Coding Moonlights

Post by Sacohen »

Where are the dimming leads to the lights plugged in?
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

into the daylight dimming on the relay box
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Moonlights

Post by rimai »

This is how I'd do:

Code: Select all

ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
if (hour()>=10 || hour()<8) ReefAngel.PWM.SetDaylight(0);
Roberto.
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

rimai wrote:This is how I'd do:

Code: Select all

ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
if (hour()>=10 || hour()<8) ReefAngel.PWM.SetDaylight(0);
So I understand the syntax. Where is the command that tells this to ramp up and then down in the evening. I tske it I have to chsnce the the 0 to 10 since I have have a meanwell driver.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Coding Moonlights

Post by lnevo »

PWMSlope.

It says to start at 6pm and go to 11pm from 0-100% and to have a 240 minute (4 hour ramp up/down) time. And to be at 0% when not during those times.
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

Roberto and Lee

Thanks for the dimming code. it works great in the morning from 6-10. However in the evening I need it to start at 100 and ramp down to 0 from 8 to 11. how can i modify?



ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
if (hour()>=5 && hour()<20) ReefAngel.PWM.SetDaylight(0);
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Coding Moonlights

Post by lnevo »

Its not?
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

lnevo wrote:Its not?
no... it started at 8pm and its currently at 20% and ramping up. I need it to be at 100 and ramp down to 0 in 3 hrs. im trying to figure out either case or if statement. but not sure how to tell it to start at 100 and finish at 0
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Coding Moonlights

Post by lnevo »

The function you posted doesnt do that...unless you have something else in your code overwriting it...

The code posted ramps up starting at 6am from 0-100% and then down from 100%-0.

The second line turns it off for the duration you wanted it at 0...
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

i adjusted to this. and it seems like its working.

if (hour()>=6 && hour()<10) ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) ); // Moonlight Between 5-10am turn the relay on
if (hour()>=20 && hour()<=23) ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) ); // From 8pm-Midnight turn the relay on
else ReefAngel.PWM.SetDaylight(0);
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

Hey Lee can you check out my other thread on the myrf question. its regarding duration.


Thanks bud
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Coding Moonlights

Post by lnevo »

Thats not going to work at all...i'm still not sure why you had an issue with the prior function unless there was other code overwriting it. What you posted will go from 9%-100% from 6am to 8am then 100%-9% from 8-10 and similar in the evening. I'll take a look at the other thread but really wasnt sure the question...
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Moonlights

Post by rimai »

Posted in the wrong thread... :oops:
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Coding Moonlights

Post by lnevo »

I think your in the wrong thread, but that would probably work.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Coding Moonlights

Post by rimai »

Sorry... :(
I edited the post above and posted again in the correct one.
Roberto.
ecam
Posts: 229
Joined: Thu Nov 15, 2012 11:27 am

Re: Coding Moonlights

Post by ecam »

Here is my complete code. Its working now. but the percentages are showing up as 255% - 100%. (shutting off at 100%). How can i get the variable to scale between 0 to 100?

Code: Select all

    #include <Salinity.h>
    #include <Relay.h>
    #include <RA_ATO.h>
    #include <RF.h>
    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>fafa
    #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>fa
    #include <IO.h>
    #include <ORP.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

    ////// Place global variable code below here
        byte myRFMode=0;
        byte myRFDuration=0;
        byte myRFSpeed=0;


    ////// 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 
      ReefAngel.WaterChangePorts = Port3Bit | Port7Bit| Port8Bit| Box1_Port1| Box1_Port4| Box1_Port6; // Turn off Return, UV, Skimmer, Heater, Sump Equipment, ATO
      ReefAngel.FeedingModePorts = Port3Bit | Port8Bit; // Turn off Return and Skimmer
      ReefAngel.LightsOnPorts = Port2Bit | Port4Bit | Port5Bit| Port6Bit;  //Turn on ATI lights, Fan and Fuge Light
      ReefAngel.OverheatShutoffPorts = Port4Bit |Port5Bit | Box1_Port1; // ATI Lights and Heaters 
      ReefAngel.TempProbe = T3_PROBE;
        ReefAngel.OverheatProbe = T3_PROBE;
          // Set the Overheat temperature setting
          InternalMemory.OverheatTemp_write( 825 );



        // Ports that are always on
        ReefAngel.Relay.On( Port3); //RETURN
        ReefAngel.Relay.On( Port7 );
        ReefAngel.Relay.On( Box1_Port2 );  // Razor Led
        ReefAngel.Relay.On( Box1_Port4 ); // Sump Equipment - UV, Pump
        ReefAngel.Relay.On( Box1_Port5 ); // MP40s   
        ReefAngel.Relay.On( Box1_Port6 ); // JBJ
        ReefAngel.Relay.On( Box1_Port3);
        ////// Place additional initialization code below here
       

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

    void loop()
    {
           ReefAngel.Relay.Off( Port1);      //  Port1 aCROPOWER DOSING...  on all the time!!!
           ReefAngel.Relay.Set( Port2, !ReefAngel.Relay.Status( Port4 ) ); //Refuge opposite of Actinic
      //  Port3 ...  pORT 3 return always on
           ReefAngel.StandardLights( Port4,10,0,20,0 ); //ATI Actinic
           ReefAngel.StandardLights( Port5,11,0,19,0 );  //ATI Daylight
           ReefAngel.StandardLights( Port6,10,0,21,0 );  //ATI Fanfa
      //  ReefAngel.Relay.On( Port7 );   UV
           ReefAngel.Relay.DelayedOn( Port8,5 ); //Skimmer
         
          //box 2
        //ReefAngel.Relay.Off( ); // Lunar Hub Not used   
           ReefAngel.StandardHeater( Box1_Port1,778,790 ); //Heater   Port #9
    //    Box1_Port2 Razor_LED (Sump)...  on all the time!!!      Port #10
  //         ReefAngel.Relay.Off( Box1_Port3); // Start with the relay off       Port #11 Moonlight
    //              if (hour()>=5 && hour()<10) ReefAngel.Relay.On(Box1_Port3); // Moonlight Between 5-10am turn the relay on
      //            if (hour()>=20 && hour()<=23) ReefAngel.Relay.On(Box1_Port3); // From 8pm-Midnight turn the relay on
    //    Box1_Port4 Sump Equipment  on all the time!!!      Port #12
    //    Box1_Port5 Ecotech MP_40 Pumps  on all the time!!!      Port #13
    //    Box1_Port6 JBJ ATO ...          on all the time!!!      Port #14
           ReefAngel.Relay.Off( Box1_Port7);  // ALK Doser ...      Port #15
           ReefAngel.Relay.Off( Box1_Port8);  // Calc Doser ...     Port #16


///moonlight dimming
                if (hour()>=6 && hour()<10) ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) ); // Moonlight Between 5-10am turn the relay on
                if (hour()>=20 && hour()<=23) ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) ); // From 8pm-Midnight turn the relay on
                else ReefAngel.PWM.SetDaylight(0);


//    ReefAngel.PWM.SetDaylight( PWMSlope(20,0,23,0,100,0,180,100) );
 //   ReefAngel.PWM.SetDaylight( PWMSlope(6,0,10,0,9,100,240,9) );
          
              //ReefAngel.Relay.off(Box1_Port3);
//  if (hour()>=10 || hour()<20) ReefAngel.PWM.SetDaylight(0);

//    ReefAngel.PWM.SetDaylight( MoonPhase()+10 );

    // ReefAngel.PWM.SetDaylight(PWMParabola(20,0,23,0,0, MoonPhase(),0 ));

//              ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
  //            if (hour()>=5 && hour()<20) ReefAngel.PWM.SetDaylight(0);
              
    //          ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) );
      //        ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) );

        ////// Place your custom code below here
       
       
          ReefAngel.RF.UseMemory = false;
          if (hour()>=6 && hour()<11)
            myRFSetMode(ReefCrest,85,10);
          else if (hour()>=11 && hour()<13)
            myRFSetMode(ReefCrest,85,10);
          else if (hour()>=13 && hour()<16)
            myRFSetMode(Smart_NTM,85,15);
          else if (hour()>=16 && hour()<19)
            myRFSetMode(ReefCrest,65,10);
          else
            myRFSetMode(Lagoon,40,10);
             
                    
        // Hardcode PH calibrations
         //ReefAngel.PHMin=544; // PH7.0
         //ReefAngel.PHMax=830; // PH10.0

         RunDosingPumps();
         LogDosingPumps();
        ////// Place your custom code above here

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

    void DrawCustomMain()
    {

        pingSerial();

        // Parameters
    #if defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 48, ReefAngel.Params,
        ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
    #else // defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 48, ReefAngel.Params );
    #endif // defined DisplayLEDPWM && ! defined RemoveAllLights
        pingSerial();
            char text[10];
              ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
              strcat(text,"  ");
              ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,93,"Salinity:");
              ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,75,93,text);
              pingSerial();
 
 
 
  
         // Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox( 12, 94, TempRelay );
        pingSerial();

        // Date and Time
        ReefAngel.LCD.DrawDate( 6, 122 );
        pingSerial();
    }

    /////////////////////////////////////////
    // Define Your dosing pumps
    /////////////////////////////////////////
    #define numDPumps 3
    byte pumpRelays[numDPumps]={ Box1_Port7, Box1_Port8,Port1Bit };
    int DPVolume[numDPumps]={ 17, 17, 7} ; // 1ml for each alk and calcium - total volume for the day
    int DPRepeat[numDPumps]={ 360, 360, 360 } ; // Repeat every 4 hrs 6x a day --- in mins
    /////////////////////////////////////////
    // Define Calibration here
    /////////////////////////////////////////
    int CalTime[numDPumps]={ 600, 600, 600 }; // 10 minutes / 10 minutes
    int CalVol[numDPumps]={ 350, 300,384 }; // 350ml / 300ml... .58 / .5/.64

    /////////////////////////////////////////
    // Function: RunDosingPumps()
    /////////////////////////////////////////
    void RunDosingPumps() {
      float rate;
      int calcTime[numDPumps];

      for (int i=0;i < numDPumps; i++) {
        rate=(float)CalVol[i]/CalTime[i];
        calcTime[i]=DPVolume[i]/rate/(1440/DPRepeat[i]);

        // Run the pumps
        ReefAngel.DosingPumpRepeat(pumpRelays[i], i*5, DPRepeat[i], calcTime[i]); // Offset between each pump is 5 minutes
      }

      // Display Time calculated in portal
      ReefAngel.CustomVar[0]=calcTime[0];
      ReefAngel.CustomVar[1]=calcTime[1];
      ReefAngel.CustomVar[2]=calcTime[2];
    }

    /////////////////////////////////////////
    // Function: LogDosingPumps()
    /////////////////////////////////////////
    void LogDosingPumps() {
      static time_t pumpTimer[numDPumps];
      static boolean pumpStatus[numDPumps];
      float rate;

      for (int i=0;i< numDPumps;i++) {
        if (ReefAngel.Relay.Status(pumpRelays[i])) {
          if (!pumpStatus[i]) {
            pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
            pumpStatus[i]=true;
          }
        } else {
          if (pumpStatus[i]) {
            pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
            pumpStatus[i]=false;
       
            rate=(float)CalVol[i]/CalTime[i];

            // Report How much volume has been dosed per day.
            // Could make this in minutes... excercise for the reader..
            ReefAngel.CustomVar[3]=pumpTimer[0]*rate;
            ReefAngel.CustomVar[4]=pumpTimer[1]*rate; 
            ReefAngel.CustomVar[5]=pumpTimer[2]*rate; 
          }
       }
     
        // Clear timer at end of day
        if (now()%SECS_PER_DAY==SECS_PER_DAY-1) pumpTimer[i]=0;
      } 
    }


        void DrawCustomGraph()
        {
        }

        void myRFSetMode(byte m, byte s, byte d)
        {
          if (m!=myRFMode || s!=myRFSpeed || d!=myRFDuration || millis()<5000)
          {
            myRFMode=m;
            myRFSpeed=s;
            myRFDuration=d;
            ReefAngel.RF.SetMode(m,s,d);
          }
        }


[code]
    #include <Salinity.h>
    #include <Relay.h>
    #include <RA_ATO.h>
    #include <RF.h>
    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>fafa
    #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>fa
    #include <IO.h>
    #include <ORP.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

    ////// Place global variable code below here
        byte myRFMode=0;
        byte myRFDuration=0;
        byte myRFSpeed=0;


    ////// 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 
      ReefAngel.WaterChangePorts = Port3Bit | Port7Bit| Port8Bit| Box1_Port1| Box1_Port4| Box1_Port6; // Turn off Return, UV, Skimmer, Heater, Sump Equipment, ATO
      ReefAngel.FeedingModePorts = Port3Bit | Port8Bit; // Turn off Return and Skimmer
      ReefAngel.LightsOnPorts = Port2Bit | Port4Bit | Port5Bit| Port6Bit;  //Turn on ATI lights, Fan and Fuge Light
      ReefAngel.OverheatShutoffPorts = Port4Bit |Port5Bit | Box1_Port1; // ATI Lights and Heaters 
      ReefAngel.TempProbe = T3_PROBE;
        ReefAngel.OverheatProbe = T3_PROBE;
          // Set the Overheat temperature setting
          InternalMemory.OverheatTemp_write( 825 );



        // Ports that are always on
        ReefAngel.Relay.On( Port3); //RETURN
        ReefAngel.Relay.On( Port7 );
        ReefAngel.Relay.On( Box1_Port2 );  // Razor Led
        ReefAngel.Relay.On( Box1_Port4 ); // Sump Equipment - UV, Pump
        ReefAngel.Relay.On( Box1_Port5 ); // MP40s   
        ReefAngel.Relay.On( Box1_Port6 ); // JBJ
        ReefAngel.Relay.On( Box1_Port3);
        ////// Place additional initialization code below here
       

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

    void loop()
    {
           ReefAngel.Relay.Off( Port1);      //  Port1 aCROPOWER DOSING...  on all the time!!!
           ReefAngel.Relay.Set( Port2, !ReefAngel.Relay.Status( Port4 ) ); //Refuge opposite of Actinic
      //  Port3 ...  pORT 3 return always on
           ReefAngel.StandardLights( Port4,10,0,20,0 ); //ATI Actinic
           ReefAngel.StandardLights( Port5,11,0,19,0 );  //ATI Daylight
           ReefAngel.StandardLights( Port6,10,0,21,0 );  //ATI Fanfa
      //  ReefAngel.Relay.On( Port7 );   UV
           ReefAngel.Relay.DelayedOn( Port8,5 ); //Skimmer
         
          //box 2
        //ReefAngel.Relay.Off( ); // Lunar Hub Not used   
           ReefAngel.StandardHeater( Box1_Port1,778,790 ); //Heater   Port #9
    //    Box1_Port2 Razor_LED (Sump)...  on all the time!!!      Port #10
  //         ReefAngel.Relay.Off( Box1_Port3); // Start with the relay off       Port #11 Moonlight
    //              if (hour()>=5 && hour()<10) ReefAngel.Relay.On(Box1_Port3); // Moonlight Between 5-10am turn the relay on
      //            if (hour()>=20 && hour()<=23) ReefAngel.Relay.On(Box1_Port3); // From 8pm-Midnight turn the relay on
    //    Box1_Port4 Sump Equipment  on all the time!!!      Port #12
    //    Box1_Port5 Ecotech MP_40 Pumps  on all the time!!!      Port #13
    //    Box1_Port6 JBJ ATO ...          on all the time!!!      Port #14
           ReefAngel.Relay.Off( Box1_Port7);  // ALK Doser ...      Port #15
           ReefAngel.Relay.Off( Box1_Port8);  // Calc Doser ...     Port #16


///moonlight dimming
                if (hour()>=6 && hour()<10) ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) ); // Moonlight Between 5-10am turn the relay on
                if (hour()>=20 && hour()<=23) ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) ); // From 8pm-Midnight turn the relay on
                else ReefAngel.PWM.SetDaylight(0);


//    ReefAngel.PWM.SetDaylight( PWMSlope(20,0,23,0,100,0,180,100) );
 //   ReefAngel.PWM.SetDaylight( PWMSlope(6,0,10,0,9,100,240,9) );
          
              //ReefAngel.Relay.off(Box1_Port3);
//  if (hour()>=10 || hour()<20) ReefAngel.PWM.SetDaylight(0);

//    ReefAngel.PWM.SetDaylight( MoonPhase()+10 );

    // ReefAngel.PWM.SetDaylight(PWMParabola(20,0,23,0,0, MoonPhase(),0 ));

//              ReefAngel.PWM.SetDaylight(PWMSlope(6,0,23,0,0,100,240,0));
  //            if (hour()>=5 && hour()<20) ReefAngel.PWM.SetDaylight(0);
              
    //          ReefAngel.PWM.SetDaylight( PWMParabola(20,0,23,0,100,0,100) );
      //        ReefAngel.PWM.SetDaylight( PWMParabola(6,0,10,0,9,100,9) );

        ////// Place your custom code below here
       
       
          ReefAngel.RF.UseMemory = false;
          if (hour()>=6 && hour()<11)
            myRFSetMode(ReefCrest,85,10);
          else if (hour()>=11 && hour()<13)
            myRFSetMode(ReefCrest,85,10);
          else if (hour()>=13 && hour()<16)
            myRFSetMode(Smart_NTM,85,15);
          else if (hour()>=16 && hour()<19)
            myRFSetMode(ReefCrest,65,10);
          else
            myRFSetMode(Lagoon,40,10);
             
                    
        // Hardcode PH calibrations
         //ReefAngel.PHMin=544; // PH7.0
         //ReefAngel.PHMax=830; // PH10.0

         RunDosingPumps();
         LogDosingPumps();
        ////// Place your custom code above here

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

    void DrawCustomMain()
    {

        pingSerial();

        // Parameters
    #if defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 48, ReefAngel.Params,
        ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
    #else // defined DisplayLEDPWM && ! defined RemoveAllLights
        ReefAngel.LCD.DrawMonitor( 15, 48, ReefAngel.Params );
    #endif // defined DisplayLEDPWM && ! defined RemoveAllLights
        pingSerial();
            char text[10];
              ConvertNumToString(text, ReefAngel.Params.Salinity, 10);
              strcat(text,"  ");
              ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,15,93,"Salinity:");
              ReefAngel.LCD.DrawText(DefaultFGColor,DefaultBGColor,75,93,text);
              pingSerial();
 
 
 
  
         // Main Relay Box
        byte TempRelay = ReefAngel.Relay.RelayData;
        TempRelay &= ReefAngel.Relay.RelayMaskOff;
        TempRelay |= ReefAngel.Relay.RelayMaskOn;
        ReefAngel.LCD.DrawOutletBox( 12, 94, TempRelay );
        pingSerial();

        // Date and Time
        ReefAngel.LCD.DrawDate( 6, 122 );
        pingSerial();
    }

    /////////////////////////////////////////
    // Define Your dosing pumps
    /////////////////////////////////////////
    #define numDPumps 3
    byte pumpRelays[numDPumps]={ Box1_Port7, Box1_Port8,Port1Bit };
    int DPVolume[numDPumps]={ 17, 17, 7} ; // 1ml for each alk and calcium - total volume for the day
    int DPRepeat[numDPumps]={ 360, 360, 360 } ; // Repeat every 4 hrs 6x a day --- in mins
    /////////////////////////////////////////
    // Define Calibration here
    /////////////////////////////////////////
    int CalTime[numDPumps]={ 600, 600, 600 }; // 10 minutes / 10 minutes
    int CalVol[numDPumps]={ 350, 300,384 }; // 350ml / 300ml... .58 / .5/.64

    /////////////////////////////////////////
    // Function: RunDosingPumps()
    /////////////////////////////////////////
    void RunDosingPumps() {
      float rate;
      int calcTime[numDPumps];

      for (int i=0;i < numDPumps; i++) {
        rate=(float)CalVol[i]/CalTime[i];
        calcTime[i]=DPVolume[i]/rate/(1440/DPRepeat[i]);

        // Run the pumps
        ReefAngel.DosingPumpRepeat(pumpRelays[i], i*5, DPRepeat[i], calcTime[i]); // Offset between each pump is 5 minutes
      }

      // Display Time calculated in portal
      ReefAngel.CustomVar[0]=calcTime[0];
      ReefAngel.CustomVar[1]=calcTime[1];
      ReefAngel.CustomVar[2]=calcTime[2];
    }

    /////////////////////////////////////////
    // Function: LogDosingPumps()
    /////////////////////////////////////////
    void LogDosingPumps() {
      static time_t pumpTimer[numDPumps];
      static boolean pumpStatus[numDPumps];
      float rate;

      for (int i=0;i< numDPumps;i++) {
        if (ReefAngel.Relay.Status(pumpRelays[i])) {
          if (!pumpStatus[i]) {
            pumpTimer[i]=now()-pumpTimer[i]; // Pump was off, timer is now a time
            pumpStatus[i]=true;
          }
        } else {
          if (pumpStatus[i]) {
            pumpTimer[i]=now()-pumpTimer[i]; // Pump was on, timer is now a timer
            pumpStatus[i]=false;
       
            rate=(float)CalVol[i]/CalTime[i];

            // Report How much volume has been dosed per day.
            // Could make this in minutes... excercise for the reader..
            ReefAngel.CustomVar[3]=pumpTimer[0]*rate;
            ReefAngel.CustomVar[4]=pumpTimer[1]*rate; 
            ReefAngel.CustomVar[5]=pumpTimer[2]*rate; 
          }
       }
     
        // Clear timer at end of day
        if (now()%SECS_PER_DAY==SECS_PER_DAY-1) pumpTimer[i]=0;
      } 
    }


        void DrawCustomGraph()
        {
        }

        void myRFSetMode(byte m, byte s, byte d)
        {
          if (m!=myRFMode || s!=myRFSpeed || d!=myRFDuration || millis()<5000)
          {
            myRFMode=m;
            myRFSpeed=s;
            myRFDuration=d;
            ReefAngel.RF.SetMode(m,s,d);
          }
        }

Post Reply