Page 1 of 1

Need a quick check of my code plz

Posted: Wed Feb 13, 2013 7:52 am
by mason dixon
I've copy/pasted several snippets of code from here and just want to make sure it is all in the right place and not missing anything

Code: Select all

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <Salinity.h>
#include <RF.h>
#include <IO.h>
#include <ORP.h>
#include <AI.h>
#include <PH.h>
#include <WaterLevel.h>
#include <ReefAngel.h>

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


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


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port7Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port7Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 790 );


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

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

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

void loop()
{
    ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
    ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
    ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
    ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
    ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
    ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
    ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
    ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
    ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
    ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );
   

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


 if (hour()>20 && hour()<8)
    {
      ReefAngel.PWM.SetActinic(30);
      ReefAngel.PWM.SetDaylight(30);
    }



    //*** Define only one mode ***
    //#define TUNZE_MODE_SINE // sine wave, no pulse
    //#define TUNZE_MODE_LONG // no sine wave, long pulse
    //#define TUNZE_MODE_SHORT // no sine wave, short pulse
    //#define TUNZE_MODE_LONGSINE // sine wave, long pulse
    #define TUNZE_MODE_SHORTSINE // sine wave, short pulse


    #define TUNZE_MIN 30
    #define TUNZE_MAX 85

    #define TUNZE_SINE_SEC 23400
    #define TUNZE_SINE_SYNC false

    #define TUNZE_LONGPULSE_SEC 2
    #define TUNZE_LONGPULSE_SYNC true

    #define TUNZE_SHORTPULSE_MS 500
    #define TUNZE_SHORTPULSE_SYNC true

    //PulseMinSpeed - % for minimal speed
    //PulseMaxSpeed - % for maximum speed
    //PulseDuration - Duration (milliseconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
    //PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
    byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }

    //PulseMinSpeed - % for minimal speed
    //PulseMaxSpeed - % for maximum speed
    //PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will stay at maximum speed for PulseDuration.
    //PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
    byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }


    byte TunzeSineWave(boolean isleftpump, byte minspeed, byte maxspeed, int period_sec) {
      double x,y;

      x=double(now()%(period_sec));
      x/=period_sec;
      x*=2.0*PI;
      if (!isleftpump) x+=PI; // shift the sine wave for the right pump

      y=sin(x);// y is now between -1 and 1
      y+=1.0; // y is now between 0 and 2
      y/=2.0; // y is now between 0 and 1 
     
      // now compute the tunze speed
      y*=double(maxspeed-minspeed);
      y+=double(minspeed);
     
      y+=0.5; // for proper rounding
     
      // y is now between minspeed and maxspeed, constrain for safety 
      return constrain(byte(y),30,100);
    }


    void RunTunzes() {
     
    #ifdef TUNZE_MODE_SINE
        ReefAngel.PWM.SetDaylight(TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // left tunze
        ReefAngel.PWM.SetActinic(TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_LONG
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,true)); // left tunze
        ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_SHORT
        ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,true)); // left tunze
        ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_LONGSINE
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,true)); // left tunze
        ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_SHORTSINE
        ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,true)); // left tunze
        ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
    #endif

    }



   
    

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





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

void DrawCustomMain()
{
    int x,y;
    char text[10];
    // Dimming Expansion
    x = 15;
    y = 2;
    for ( int a=0;a<6;a++ )
    {
      if ( a>2 ) x = 75;
      if ( a==3 ) y = 2;
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
      ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
      y += 10;
    }
    pingSerial();

    // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params,
    ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
    ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
    pingSerial();

    // pH Expansion
    ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,15,76, "PHE:" );
    ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,39,76, ReefAngel.Params.PHExp );
    pingSerial();

    // Main Relay Box
    byte TempRelay = ReefAngel.Relay.RelayData;
    TempRelay &= ReefAngel.Relay.RelayMaskOff;
    TempRelay |= ReefAngel.Relay.RelayMaskOn;
    ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
    pingSerial();

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

void DrawCustomGraph()
{
}

Re: Need a quick check of my code plz

Posted: Wed Feb 13, 2013 9:14 am
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 <ReefAngel.h>

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


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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port7Bit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port7Bit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  // Set the Overheat temperature setting
  InternalMemory.OverheatTemp_write( 790 );


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

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


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

void loop()
{
  ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
  ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
  ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
  ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
  ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
  ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
  ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
  ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
  ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
  ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

  if (hour()>20 && hour()<8)
  {
    ReefAngel.PWM.SetActinic(30);
    ReefAngel.PWM.SetDaylight(30);
  }
  else
  {
    RunTunzes();
  }
  ////// Place your custom code above here

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

void DrawCustomMain()
{
  int x,y;
  char text[10];
  // Dimming Expansion
  x = 15;
  y = 2;
  for ( int a=0;a<6;a++ )
  {
    if ( a>2 ) x = 75;
    if ( a==3 ) y = 2;
    ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
    ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
    ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
    y += 10;
  }
  pingSerial();

  // Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params,
  ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
  ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
  pingSerial();

  // pH Expansion
  ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,15,76, "PHE:" );
  ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,39,76, ReefAngel.Params.PHExp );
  pingSerial();

  // Main Relay Box
  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
  pingSerial();

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

void DrawCustomGraph()
{
}


//*** Define only one mode ***
//#define TUNZE_MODE_SINE // sine wave, no pulse
//#define TUNZE_MODE_LONG // no sine wave, long pulse
//#define TUNZE_MODE_SHORT // no sine wave, short pulse
//#define TUNZE_MODE_LONGSINE // sine wave, long pulse
#define TUNZE_MODE_SHORTSINE // sine wave, short pulse


#define TUNZE_MIN 30
#define TUNZE_MAX 85

#define TUNZE_SINE_SEC 23400
#define TUNZE_SINE_SYNC false

#define TUNZE_LONGPULSE_SEC 2
#define TUNZE_LONGPULSE_SYNC true

#define TUNZE_SHORTPULSE_MS 500
#define TUNZE_SHORTPULSE_SYNC true

//PulseMinSpeed - % for minimal speed
//PulseMaxSpeed - % for maximum speed
//PulseDuration - Duration (milliseconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and
//will stay at maximum speed for PulseDuration.
//PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
  byte tspeed=0;
  PulseMinSpeed=constrain(PulseMinSpeed,30,100);
  PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
  tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
  if (PulseSync)
    return tspeed;
  else
    return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}

//PulseMinSpeed - % for minimal speed
//PulseMaxSpeed - % for maximum speed
//PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will
//stay at maximum speed for PulseDuration.
//PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
  byte tspeed=0;
  PulseMinSpeed=constrain(PulseMinSpeed,30,100);
  PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
  tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
  if (PulseSync)
    return tspeed;
  else
    return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}


byte TunzeSineWave(boolean isleftpump, byte minspeed, byte maxspeed, int period_sec) {
  double x,y;

  x=double(now()%(period_sec));
  x/=period_sec;
  x*=2.0*PI;
  if (!isleftpump) x+=PI; // shift the sine wave for the right pump

  y=sin(x);// y is now between -1 and 1
  y+=1.0; // y is now between 0 and 2
  y/=2.0; // y is now between 0 and 1 

  // now compute the tunze speed
  y*=double(maxspeed-minspeed);
  y+=double(minspeed);

  y+=0.5; // for proper rounding

  // y is now between minspeed and maxspeed, constrain for safety 
  return constrain(byte(y),30,100);
}


void RunTunzes() {

#ifdef TUNZE_MODE_SINE
  ReefAngel.PWM.SetDaylight(TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // left tunze
  ReefAngel.PWM.SetActinic(TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // right tunze
#endif

#ifdef TUNZE_MODE_LONG
  ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,true)); // left tunze
  ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
#endif

#ifdef TUNZE_MODE_SHORT
  ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,true)); // left tunze
  ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
#endif

#ifdef TUNZE_MODE_LONGSINE
  ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,true)); // left tunze
  ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
#endif

#ifdef TUNZE_MODE_SHORTSINE
  ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,true)); // left tunze
  ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
#endif

}

Re: Need a quick check of my code plz

Posted: Wed Feb 13, 2013 9:38 am
by mason dixon
Thanks Roberto,

I'd like to add one more snippet of code.

I'd like to use one of the float switches on my display tank to turn off the return pump (port 6) if the overflow is blocked. I won't need to use the 2nd float switch as of now.

Thanks

Re: Need a quick check of my code plz

Posted: Wed Feb 13, 2013 12:15 pm
by rimai
Try this:

Code: Select all

ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());

Re: Need a quick check of my code plz

Posted: Wed Feb 13, 2013 12:42 pm
by mason dixon
thanks again, just to be sure, I added that last snippet here

Code: Select all

    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>
    #include <InternalEEPROM.h>
    #include <RA_NokiaLCD.h>
    #include <RA_ATO.h>
    #include <RA_Joystick.h>
    #include <LED.h>
    #include <RA_TempSensor.h>
    #include <Relay.h>
    #include <RA_PWM.h>
    #include <Timer.h>
    #include <Memory.h>
    #include <InternalEEPROM.h>
    #include <RA_Colors.h>
    #include <RA_CustomColors.h>
    #include <Salinity.h>
    #include <RF.h>
    #include <IO.h>
    #include <ORP.h>
    #include <AI.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

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


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


    void setup()
    {
      // This must be the first line
      ReefAngel.Init();  //Initialize controller
      // Ports toggled in Feeding Mode
      ReefAngel.FeedingModePorts = Port7Bit;
      // Ports toggled in Water Change Mode
      ReefAngel.WaterChangePorts = Port7Bit;
      // Ports toggled when Lights On / Off menu entry selected
      ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
      // Ports turned off when Overheat temperature exceeded
      ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
      // Use T1 probe as temperature and overheat functions
      ReefAngel.TempProbe = T1_PROBE;
      ReefAngel.OverheatProbe = T1_PROBE;
      // Set the Overheat temperature setting
      InternalMemory.OverheatTemp_write( 790 );


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

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

      ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());//Turns off return pump if DT is flooding

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

    void loop()
    {
      ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
      ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
      ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
      ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
      ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
      ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
      ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
      ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
      ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
      ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

      if (hour()>20 && hour()<8)
      {
        ReefAngel.PWM.SetActinic(30);
        ReefAngel.PWM.SetDaylight(30);
      }
      else
      {
        RunTunzes();
      }
      ////// Place your custom code above here

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

    void DrawCustomMain()
    {
      int x,y;
      char text[10];
      // Dimming Expansion
      x = 15;
      y = 2;
      for ( int a=0;a<6;a++ )
      {
        if ( a>2 ) x = 75;
        if ( a==3 ) y = 2;
        ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x,y,"Ch :" );
        ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+12,y,a );
        ReefAngel.LCD.DrawText( COLOR_DARKGOLDENROD,DefaultBGColor,x+24,y,ReefAngel.PWM.GetChannelValue(a) );
        y += 10;
      }
      pingSerial();

      // Parameters
    #if defined DisplayLEDPWM && ! defined RemoveAllLights
      ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params,
      ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
    #else // defined DisplayLEDPWM && ! defined RemoveAllLights
      ReefAngel.LCD.DrawMonitor( 15, 39, ReefAngel.Params );
    #endif // defined DisplayLEDPWM && ! defined RemoveAllLights
      pingSerial();

      // pH Expansion
      ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,15,76, "PHE:" );
      ReefAngel.LCD.DrawText( COLOR_MEDIUMSEAGREEN,DefaultBGColor,39,76, ReefAngel.Params.PHExp );
      pingSerial();

      // Main Relay Box
      byte TempRelay = ReefAngel.Relay.RelayData;
      TempRelay &= ReefAngel.Relay.RelayMaskOff;
      TempRelay |= ReefAngel.Relay.RelayMaskOn;
      ReefAngel.LCD.DrawOutletBox( 12, 93, TempRelay );
      pingSerial();

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

    void DrawCustomGraph()
    {
    }


    //*** Define only one mode ***
    //#define TUNZE_MODE_SINE // sine wave, no pulse
    //#define TUNZE_MODE_LONG // no sine wave, long pulse
    //#define TUNZE_MODE_SHORT // no sine wave, short pulse
    //#define TUNZE_MODE_LONGSINE // sine wave, long pulse
    #define TUNZE_MODE_SHORTSINE // sine wave, short pulse


    #define TUNZE_MIN 30
    #define TUNZE_MAX 85

    #define TUNZE_SINE_SEC 23400
    #define TUNZE_SINE_SYNC false

    #define TUNZE_LONGPULSE_SEC 2
    #define TUNZE_LONGPULSE_SYNC true

    #define TUNZE_SHORTPULSE_MS 500
    #define TUNZE_SHORTPULSE_SYNC true

    //PulseMinSpeed - % for minimal speed
    //PulseMaxSpeed - % for maximum speed
    //PulseDuration - Duration (milliseconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and
    //will stay at maximum speed for PulseDuration.
    //PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
    byte TunzeShortPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(millis()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }

    //PulseMinSpeed - % for minimal speed
    //PulseMaxSpeed - % for maximum speed
    //PulseDuration - Duration (seconds) in which each pulse will be held. The pump will stay at minimal speed for PulseDuration and will
    //stay at maximum speed for PulseDuration.
    //PulseSync - true if you want to sync pumps to same cycle. one false and one true if you want to anti-sync pumps.
    byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }


    byte TunzeSineWave(boolean isleftpump, byte minspeed, byte maxspeed, int period_sec) {
      double x,y;

      x=double(now()%(period_sec));
      x/=period_sec;
      x*=2.0*PI;
      if (!isleftpump) x+=PI; // shift the sine wave for the right pump

      y=sin(x);// y is now between -1 and 1
      y+=1.0; // y is now between 0 and 2
      y/=2.0; // y is now between 0 and 1

      // now compute the tunze speed
      y*=double(maxspeed-minspeed);
      y+=double(minspeed);

      y+=0.5; // for proper rounding

      // y is now between minspeed and maxspeed, constrain for safety
      return constrain(byte(y),30,100);
    }


    void RunTunzes() {

    #ifdef TUNZE_MODE_SINE
      ReefAngel.PWM.SetDaylight(TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // left tunze
      ReefAngel.PWM.SetActinic(TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_LONG
      ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,true)); // left tunze
      ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_SHORT
      ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,true)); // left tunze
      ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TUNZE_MAX,TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_LONGSINE
      ReefAngel.PWM.SetDaylight(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,true)); // left tunze
      ReefAngel.PWM.SetActinic(TunzeLongPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_LONGPULSE_SEC,TUNZE_LONGPULSE_SYNC)); // right tunze
    #endif

    #ifdef TUNZE_MODE_SHORTSINE
      ReefAngel.PWM.SetDaylight(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(true,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,true)); // left tunze
      ReefAngel.PWM.SetActinic(TunzeShortPulse(TUNZE_MIN,TunzeSineWave(TUNZE_SINE_SYNC,TUNZE_MIN,TUNZE_MAX,TUNZE_SINE_SEC),TUNZE_SHORTPULSE_MS,TUNZE_SHORTPULSE_SYNC)); // right tunze
    #endif

    }
Good to go?

Re: Need a quick check of my code plz

Posted: Wed Feb 13, 2013 12:47 pm
by rimai
no, it has to be on the loop section.
The setup section only happens once when the controller boots up.

Re: Need a quick check of my code plz

Posted: Mon Feb 18, 2013 8:26 am
by mason dixon
Roberto, does my wiring look ok? My lights don't seem to be dimming, they just turn on and off. I'm using the above code.

My whites are on channel 0 on the pwm dimming module. My royal blues are on channel 1. They are hooked up to meanwell drivers, I tried switching the dimming wires around to no avail.

My accent colors are on channel 2 and my act/uv are on channel 3. I'm hooking them up with steves leds drivers. Is my diagram the correct way to hook them up?

Image

Re: Need a quick check of my code plz

Posted: Mon Feb 18, 2013 8:55 am
by rimai
Yes, it looks good to me.

Re: Need a quick check of my code plz

Posted: Tue Feb 26, 2013 10:30 am
by mason dixon
Roberto, thanks so much for your help. I tried the above code on the tunzes and don't think it is going to work for my system. How would I code this?

I would like my tunzes to go from 30-60 percent in 3 seconds and back down to 30 in 4 seconds and just keep repeating that during hours 9-14 and 18-20. During hours 14-18 I would like them to go from 30-90 in 3 seconds and back down to 30 in 4 seconds. I would also like the pumps to turn off for 10 minutes while I feed at 10 and at 16:30. At night I would like them to stay at 30 percent between 20 and 9.

Re: Need a quick check of my code plz

Posted: Tue Feb 26, 2013 10:43 am
by rimai
Try this:

Code: Select all

      if (hour()>=9 && hour()<14)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
      }
      else if (hour()>=14 && hour()<18)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 90, 3, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 90, 3, true));
      }
      else if (hour()>=18 && hour()<20)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
      }
      else
      {
        ReefAngel.PWM.SetActinic(30);
        ReefAngel.PWM.SetDaylight(30);
      }
It doesn't have the feeding mode turn off though.

Re: Need a quick check of my code plz

Posted: Tue Feb 26, 2013 11:00 am
by mason dixon
Thanks again and just to be sure its in the right place

Code: Select all

    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>
    #include <InternalEEPROM.h>
    #include <RA_NokiaLCD.h>
    #include <RA_ATO.h>
    #include <RA_Joystick.h>
    #include <LED.h>
    #include <RA_TempSensor.h>
    #include <Relay.h>
    #include <RA_PWM.h>
    #include <Timer.h>
    #include <Memory.h>
    #include <InternalEEPROM.h>
    #include <RA_Colors.h>
    #include <RA_CustomColors.h>
    #include <Salinity.h>
    #include <RF.h>
    #include <IO.h>
    #include <ORP.h>
    #include <AI.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

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


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


    void setup()
    {
      // This must be the first line
      ReefAngel.Init();  //Initialize controller
      // Ports toggled in Feeding Mode
      ReefAngel.FeedingModePorts = Port7Bit;
      // Ports toggled in Water Change Mode
      ReefAngel.WaterChangePorts = Port7Bit;
      // Ports toggled when Lights On / Off menu entry selected
      ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
      // Ports turned off when Overheat temperature exceeded
      ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
      // Use T1 probe as temperature and overheat functions
      ReefAngel.TempProbe = T1_PROBE;
      ReefAngel.OverheatProbe = T1_PROBE;
      // Set the Overheat temperature setting
      InternalMemory.OverheatTemp_write( 790 );


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

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

      

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

    void loop()
    {
      ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
      ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
      ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
      ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
      ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
      ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
      ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
      ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
      ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
      ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

      ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());//Turns off return pump if DT is flooding

                if (hour()>=9 && hour()<14)
          {
            ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
            ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
          }
          else if (hour()>=14 && hour()<18)
          {
            ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 90, 3, true));
            ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 90, 3, true));
          }
          else if (hour()>=18 && hour()<20)
          {
            ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
            ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
          }
          else
          {
            ReefAngel.PWM.SetActinic(30);
            ReefAngel.PWM.SetDaylight(30);
          }

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

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

    

Re: Need a quick check of my code plz

Posted: Tue Feb 26, 2013 11:21 am
by lnevo
looks ok to me.

Re: Need a quick check of my code plz

Posted: Wed Feb 27, 2013 6:32 am
by mason dixon
Got the error message "TunzeLongPulse not declared in scope"

Re: Need a quick check of my code plz

Posted: Wed Feb 27, 2013 9:50 am
by rimai
Oh, you need to add the function to the end of your code...
These functions are not in the libraries yet.
They will be in the next release, but in the mean time, just add this to the very end of your code after the last }

Code: Select all

    byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }

Re: Need a quick check of my code plz

Posted: Mon Apr 22, 2013 5:54 am
by mason dixon
I would like for my tunze pumps to turn off for 10 mins at 10:28am, 11:58pm, 1:28pm, 258pm. How is that coded? Thanks

Code: Select all

        #include <ReefAngel_Features.h>
        #include <Globals.h>
        #include <RA_Wifi.h>
        #include <Wire.h>
        #include <OneWire.h>
        #include <Time.h>
        #include <DS1307RTC.h>
        #include <InternalEEPROM.h>
        #include <RA_NokiaLCD.h>
        #include <RA_ATO.h>
        #include <RA_Joystick.h>
        #include <LED.h>
        #include <RA_TempSensor.h>
        #include <Relay.h>
        #include <RA_PWM.h>
        #include <Timer.h>
        #include <Memory.h>
        #include <InternalEEPROM.h>
        #include <RA_Colors.h>
        #include <RA_CustomColors.h>
        #include <Salinity.h>
        #include <RF.h>
        #include <IO.h>
        #include <ORP.h>
        #include <AI.h>
        #include <PH.h>
        #include <WaterLevel.h>
        #include <ReefAngel.h>

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


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


        void setup()
        {
          // This must be the first line
          ReefAngel.Init();  //Initialize controller
          // Ports toggled in Feeding Mode
          ReefAngel.FeedingModePorts = Port7Bit;
          // Ports toggled in Water Change Mode
          ReefAngel.WaterChangePorts = Port7Bit;
          // Ports toggled when Lights On / Off menu entry selected
          ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
          // Ports turned off when Overheat temperature exceeded
          ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
          // Use T1 probe as temperature and overheat functions
          ReefAngel.TempProbe = T1_PROBE;
          ReefAngel.OverheatProbe = T1_PROBE;
          // Set the Overheat temperature setting
          InternalMemory.OverheatTemp_write( 790 );


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

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

         

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

        void loop()
        {
          ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
          ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
          ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
          ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
          ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
          ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
          ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
          ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
          ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
          ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

          ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());//Turns off return pump if DT is flooding

                    if (hour()>=9 && hour()<14)
              {
                ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
                ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
              }
              else if (hour()>=14 && hour()<18)
              {
                ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 90, 3, true));
                ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 90, 3, true));
              }
              else if (hour()>=18 && hour()<20)
              {
                ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
                ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
              }
              else
              {
                ReefAngel.PWM.SetActinic(30);
                ReefAngel.PWM.SetDaylight(30);
              }
        
	byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
        {
          byte tspeed=0;
          PulseMinSpeed=constrain(PulseMinSpeed,30,100);
          PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
          tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
          if (PulseSync)
            return tspeed;
          else
            return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
        }

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

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

        

Re: Need a quick check of my code plz

Posted: Mon Apr 22, 2013 7:37 am
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 <ReefAngel.h>

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


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


void setup()
{
  // This must be the first line
  ReefAngel.Init();  //Initialize controller
  // Ports toggled in Feeding Mode
  ReefAngel.FeedingModePorts = Port7Bit;
  // Ports toggled in Water Change Mode
  ReefAngel.WaterChangePorts = Port7Bit;
  // Ports toggled when Lights On / Off menu entry selected
  ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
  // Ports turned off when Overheat temperature exceeded
  ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
  // Use T1 probe as temperature and overheat functions
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  // Set the Overheat temperature setting
  InternalMemory.OverheatTemp_write( 790 );


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

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



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

void loop()
{
  ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
  ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
  ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
  ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
  ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
  ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
  ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
  ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
  ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
  ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

  ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());//Turns off return pump if DT is flooding

  if (hour()>=9 && hour()<14)
  {
    ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
    ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
  }
  else if (hour()>=14 && hour()<18)
  {
    ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 90, 3, true));
    ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 90, 3, true));
  }
  else if (hour()>=18 && hour()<20)
  {
    ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
    ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
  }
  else
  {
    ReefAngel.PWM.SetActinic(30);
    ReefAngel.PWM.SetDaylight(30);
  }
  
  if (now()%37680<600 || now()%43080<600 || now()%48480<600 || now()%53880<600)
  {
    ReefAngel.PWM.SetActinic(0);
    ReefAngel.PWM.SetDaylight(0);
  }
  ////// Place your custom code above here

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

byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
{
  byte tspeed=0;
  PulseMinSpeed=constrain(PulseMinSpeed,30,100);
  PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
  tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
  if (PulseSync)
    return tspeed;
  else
    return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
}

Re: Need a quick check of my code plz

Posted: Mon Apr 22, 2013 7:45 am
by mason dixon
thanks, another question, i was just going through the sunrise/sunset tutorial

does this need to be part of my code?

Code: Select all

Expansion Code Header

// This is just how we are going to reference the PWM expansion ports within the code.
// You can change the labels if you would like, just as long as they are changed all throughout the code too.
#define LEDPWM0 0
#define LEDPWM1 1
#define LEDPWM2 2
#define LEDPWM3 3
#define LEDPWM4 4
#define LEDPWM5 5

// Initial values to all 6 channels at startup. They will always be 0.
byte PWMChannel[]={
  0,0,0,0,0,0};

//End of PWM Expansion Code Header

Re: Need a quick check of my code plz

Posted: Mon Apr 22, 2013 7:49 am
by rimai
The code I mentioned above is already doing sunset/sunrise.

Re: Need a quick check of my code plz

Posted: Tue Jan 21, 2014 7:36 am
by mason dixon
Roberto, can you add a bit of code to this please.


I need port 8 on my relay box to come on once every hour for 25 seconds. Otherwise it should be off. Thanks



Code: Select all

    #include <ReefAngel_Features.h>
    #include <Globals.h>
    #include <RA_Wifi.h>
    #include <Wire.h>
    #include <OneWire.h>
    #include <Time.h>
    #include <DS1307RTC.h>
    #include <InternalEEPROM.h>
    #include <RA_NokiaLCD.h>
    #include <RA_ATO.h>
    #include <RA_Joystick.h>
    #include <LED.h>
    #include <RA_TempSensor.h>
    #include <Relay.h>
    #include <RA_PWM.h>
    #include <Timer.h>
    #include <Memory.h>
    #include <InternalEEPROM.h>
    #include <RA_Colors.h>
    #include <RA_CustomColors.h>
    #include <Salinity.h>
    #include <RF.h>
    #include <IO.h>
    #include <ORP.h>
    #include <AI.h>
    #include <PH.h>
    #include <WaterLevel.h>
    #include <ReefAngel.h>

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


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


    void setup()
    {
      // This must be the first line
      ReefAngel.Init();  //Initialize controller
      // Ports toggled in Feeding Mode
      ReefAngel.FeedingModePorts = Port7Bit;
      // Ports toggled in Water Change Mode
      ReefAngel.WaterChangePorts = Port7Bit;
      // Ports toggled when Lights On / Off menu entry selected
      ReefAngel.LightsOnPorts = Port1Bit | Port2Bit | Port3Bit;
      // Ports turned off when Overheat temperature exceeded
      ReefAngel.OverheatShutoffPorts = Port6Bit | Port8Bit;
      // Use T1 probe as temperature and overheat functions
      ReefAngel.TempProbe = T1_PROBE;
      ReefAngel.OverheatProbe = T1_PROBE;
      // Set the Overheat temperature setting
      InternalMemory.OverheatTemp_write( 790 );


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

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



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

    void loop()
    {
      ReefAngel.StandardLights( Port1,9,0,20,0 );//4500
      ReefAngel.StandardLights( Port2,9,0,20,0 );//RB
      ReefAngel.StandardLights( Port3,8,0,23,0 );//Blue 1 & 2, Act, UV
      ReefAngel.StandardLights( Port4,20,0,9,0 );//ATS
      ReefAngel.PWM.SetChannel( 0, PWMParabola(9,0,20,0,15,80,15) );//4500
      ReefAngel.PWM.SetChannel( 1, PWMParabola(9,0,20,0,15,100,15) );//RB
      ReefAngel.PWM.SetChannel( 2, PWMParabola(9,0,20,0,15,100,15) );//BLUE 1 & 2
      ReefAngel.PWM.SetChannel( 3, PWMParabola(8,0,23,0,15,100,15) );//ACT & UV
      ReefAngel.PWM.SetChannel( 4, PWMParabola(9,0,20,0,15,100,15) );
      ReefAngel.PWM.SetChannel( 5, PWMSlope(20,0,10,0,15,70,20,15) );

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

      ReefAngel.Relay.Set(Port6,ReefAngel.HighATO.IsActive());//Turns off return pump if DT is flooding

      if (hour()>=9 && hour()<14)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
      }
      else if (hour()>=14 && hour()<18)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 90, 3, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 90, 3, true));
      }
      else if (hour()>=18 && hour()<20)
      {
        ReefAngel.PWM.SetActinic(TunzeLongPulse(30, 60, 4, true));
        ReefAngel.PWM.SetDaylight(TunzeLongPulse(30, 60, 4, true));
      }
      else
      {
        ReefAngel.PWM.SetActinic(30);
        ReefAngel.PWM.SetDaylight(30);
      }
     
      if (now()%37680<600 || now()%43080<600 || now()%48480<600 || now()%53880<600)
      {
        ReefAngel.PWM.SetActinic(0);
        ReefAngel.PWM.SetDaylight(0);
      }
      ////// Place your custom code above here

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

    byte TunzeLongPulse(byte PulseMinSpeed, byte PulseMaxSpeed, int PulseDuration, boolean PulseSync)
    {
      byte tspeed=0;
      PulseMinSpeed=constrain(PulseMinSpeed,30,100);
      PulseMaxSpeed=constrain(PulseMaxSpeed,30,100);
      tspeed=(now()%(PulseDuration*2)<PulseDuration?PulseMinSpeed:PulseMaxSpeed);
      if (PulseSync)
        return tspeed;
      else
        return (tspeed==PulseMinSpeed)?PulseMaxSpeed:PulseMinSpeed;
    }

Re: Need a quick check of my code plz

Posted: Tue Jan 21, 2014 9:05 am
by rimai
Add this to your loop():

Code: Select all

ReefAngel.Relay.Set(Port8,now()%3600<25);

Re: Need a quick check of my code plz

Posted: Tue Jan 21, 2014 10:00 am
by lnevo
You could also use this:

Code: Select all

ReefAngel.DosingPumpRepeat(Port8,0,60,25);

Re: Need a quick check of my code plz

Posted: Tue Jan 21, 2014 10:02 am
by rimai
lnevo wrote:You could also use this:

Code: Select all

ReefAngel.DosingPumpRepeat(Port8,0,60,25);
Nice :mrgreen:

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:24 pm
by mason dixon
Hi Roberto,

I'm redoing a bunch of stuff and started over with the wizard. When I went to compile it, this error message popped up

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 = Port5Bit;
    ReefAngel.FeedingModePortsE[0] = 0;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port5Bit | Port6Bit;
    ReefAngel.WaterChangePortsE[0] = 0;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
    ReefAngel.LightsOnPortsE[0] = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit;
    ReefAngel.OverheatShutoffPortsE[0] = 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( 874 );

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


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

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

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

void loop()
{
    ReefAngel.StandardLights( Port1,12,0,22,0 );
    ReefAngel.StandardLights( Port2,13,0,20,0 );
    ReefAngel.StandardHeater( Port3,760,770 );
    ReefAngel.StandardHeater( Port4,760,770 );
    ReefAngel.StandardLights( Port5,0,0,21,0 );
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( Constant,50,10 );
    ReefAngel.DCPump.DaylightChannel = None;
    ReefAngel.DCPump.ActinicChannel = None;
    ////// Place your custom code below here
    

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

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


Image

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:32 pm
by rimai
Do you have the relay expansion module?

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:40 pm
by mason dixon
I've just got the main relay box with the 8 outlets actually

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:42 pm
by rimai
You must assign a function to at least one of the ports in the relay expansion.

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:45 pm
by mason dixon
The wizard doesn't have a way to select that I'm not using an expansion relay box. I only have the main relay box that came with the reefangel.

Re: Need a quick check of my code plz

Posted: Fri Mar 07, 2014 1:46 pm
by mason dixon
I figured it out, had expansion selected at the beginning of setup, sorry I'm a doofus