Adding to code

Do you have a question on how to do something.
Ask in here.
Post Reply
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Adding to code

Post by dtzreef »

So, this is the code I am running now:
#include <ReefAngel_Features.h>
#include <RA_Colors.h>
#include <RA_CustomColors.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_Colors.h>
#include <RA_CustomColors.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 <ReefAngel.h>

byte wmport=Port5;
boolean wmdelay=false;

void DrawCustomMain()
{

ReefAngel.LCD.DrawDate(6, 120);
ReefAngel.LCD.DrawLargeText(COLOR_DARKTURQUOISE, COLOR_WHITE, 4, 4 , "DTZ REEF ANGEL");
ReefAngel.LCD.Clear(COLOR_MAROON, 1, 13, 132, 13);
ReefAngel.LCD.Clear(COLOR_MAROON, 10, 75, 119, 75);
ReefAngel.LCD.Clear(COLOR_MAROON, 10, 118, 119, 118);
pingSerial();


ReefAngel.LCD.DrawText(COLOR_GOLDENROD, COLOR_WHITE, 8, 15, "Main Tank:");
char text[7];
ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
pingSerial();
ReefAngel.LCD.DrawText(COLOR_GOLDENROD, DefaultBGColor, 88, 15, text);
pingSerial();

ReefAngel.LCD.DrawText(COLOR_MEDIUMSEAGREEN, COLOR_WHITE, 50, 46, "pH:");
ConvertNumToString(text, ReefAngel.Params.PH, 100);

ReefAngel.LCD.DrawText(PHColor, DefaultBGColor, 88, 46, text);
pingSerial();

ReefAngel.LCD.DrawText(COLOR_RED, COLOR_WHITE,8,25,"Room Temp:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_RED, 88, 25, 10);

ReefAngel.LCD.DrawText(COLOR_DARKORCHID, COLOR_WHITE,8,36,"Refugium:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], T2TempColor, 88, 36, 10);

pingSerial();
// Display arrows for Wavemaker
ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 38, 57,"WAVE FLOW:");
if (bitRead(ReefAngel.Relay.RelayData,Port5-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"----->"); //port 5 on
else if (bitRead(ReefAngel.Relay.RelayData,Port6-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"<-----"); //port 6 on
else ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67," 00000 "); //port5 and port 6 off, wavemaker delay
//show the timer for wavemaker
int t=ReefAngel.Timer[1].Trigger-now();
if (t>=0)
ReefAngel.LCD.Clear(255,105,64,135,74);
ReefAngel.LCD.DrawText(APColor, COLOR_KHAKI,105,64,t);
pingSerial();

byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
// ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
ReefAngel.Init(); //Initialize controller

ReefAngel.FeedingModePorts = Port2Bit | Port5Bit | Port6Bit;
ReefAngel.WaterChangePorts = Port2Bit | Port5Bit | Port6Bit | Port8Bit;
ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit | Port7Bit;
ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
randomSeed(analogRead(0));
ReefAngel.Timer[1].SetInterval(random(30,45));
ReefAngel.Timer[1].Start();
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write( 805 );
ReefAngel.Relay.On(Port5);
ReefAngel.Relay.On(Port2);
ReefAngel.Relay.On(Port8);
}

void loop()
{
// Specific functions
ReefAngel.StandardATO(Port1,240);
ReefAngel.StandardLights(Port3,10,0,22,0);
ReefAngel.StandardLights(Port4,11,0,21,0);
ReefAngel.StandardHeater(Port7,770,790);

//wavemaker timers and slow down at night
if ( ReefAngel.Timer[1].IsTriggered() )
{
if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a
{
if (wmdelay)
{
ReefAngel.Timer[1].SetInterval(60); // wm night delay
ReefAngel.Timer[1].Start();
ReefAngel.Relay.Off(Port5);
ReefAngel.Relay.Off(Port6);
if (wmport==Port5) wmport=Port6;
else wmport=Port5;
wmdelay=false;
}
else
{
ReefAngel.Timer[1].SetInterval(20); // short wave
ReefAngel.Timer[1].Start();
ReefAngel.Relay.On(wmport);
wmdelay=true;
}
}
else
{
//8a-9p normal wave settings
ReefAngel.Timer[1].SetInterval(random(35,50));
ReefAngel.Timer[1].Start();
ReefAngel.Relay.Toggle(Port5);
if bitRead(ReefAngel.Relay.RelayData,Port5-1) ReefAngel.Relay.Off(Port6);
else ReefAngel.Relay.On(Port6);
}
}
ReefAngel.Portal("dtzreef");
ReefAngel.ShowInterface();
}


I would like to add "Lights On" and "Lights Off" mode to the menu and a 5 minute delay on Port #2 (skimmer) after water change and feeding mode. I know it has something to do with RAGen, but I just cannot figure out how to add these features. Everything else has worked out great, I just need a little tweaking. Please help.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

I forgot I need to add "Set Date/Time" to Menu......
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Adding to code

Post by rimai »

Try this:

Code: Select all

#include <ReefAngel_Features.h>
#include <RA_Colors.h>
#include <RA_CustomColors.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_Colors.h>
#include <RA_CustomColors.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 <ReefAngel.h>

byte wmport=Port5;
boolean wmdelay=false;


#include <avr/pgmspace.h>
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "ATO Clear";
prog_char menu4_label[] PROGMEM = "Overheat Clear";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Lights On";
prog_char menu7_label[] PROGMEM = "Lights Off";
prog_char menu8_label[] PROGMEM = "Date/Time";
prog_char menu9_label[] PROGMEM = "Version";

PROGMEM const char *menu_items[] = {
  menu1_label, menu2_label, menu3_label, menu4_label, menu5_label, menu6_label, menu7_label, menu8_label, menu9_label  };

void MenuEntry1()
{
  ReefAngel.FeedingModeStart();

}
void MenuEntry2()
{
  ReefAngel.WaterChangeModeStart();

}
void MenuEntry3()
{
  ReefAngel.ATOClear();
  ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
}
void MenuEntry4()
{
  ReefAngel.OverheatClear();
  ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry5()
{
  ReefAngel.SetupCalibratePH();
  ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;

}

void MenuEntry6()
{
  ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
#ifdef RelayExp
  for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
  {
    ReefAngel.Relay.RelayMaskOnE[i] = ReefAngel.LightsOnPortsE[i];
  }
#endif  // RelayExp
  ReefAngel.Relay.Write();
}

void MenuEntry7()
{
  ReefAngel.Relay.RelayMaskOn = 0;
#ifdef RelayExp
  for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
  {
    ReefAngel.Relay.RelayMaskOnE[i] = 0;
  }
#endif  // RelayExp
  ReefAngel.Relay.Write();
}

void MenuEntry8()
{
  ReefAngel.SetupDateTime();
  ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}

void MenuEntry9()
{
  ReefAngel.DisplayVersion();
}




void DrawCustomMain()
{

  ReefAngel.LCD.DrawDate(6, 120);
  ReefAngel.LCD.DrawLargeText(COLOR_DARKTURQUOISE, COLOR_WHITE, 4, 4 , "DTZ REEF ANGEL");
  ReefAngel.LCD.Clear(COLOR_MAROON, 1, 13, 132, 13);
  ReefAngel.LCD.Clear(COLOR_MAROON, 10, 75, 119, 75);
  ReefAngel.LCD.Clear(COLOR_MAROON, 10, 118, 119, 118);
  pingSerial();


  ReefAngel.LCD.DrawText(COLOR_GOLDENROD, COLOR_WHITE, 8, 15, "Main Tank:");
  char text[7];
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  pingSerial();
  ReefAngel.LCD.DrawText(COLOR_GOLDENROD, DefaultBGColor, 88, 15, text);
  pingSerial(); 

  ReefAngel.LCD.DrawText(COLOR_MEDIUMSEAGREEN, COLOR_WHITE, 50, 46, "pH:");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);

  ReefAngel.LCD.DrawText(PHColor, DefaultBGColor, 88, 46, text);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_RED, COLOR_WHITE,8,25,"Room Temp:");
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_RED, 88, 25, 10);

  ReefAngel.LCD.DrawText(COLOR_DARKORCHID, COLOR_WHITE,8,36,"Refugium:");
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], T2TempColor, 88, 36, 10);

  pingSerial();
  // Display arrows for Wavemaker
  ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 38, 57,"WAVE FLOW:");
  if (bitRead(ReefAngel.Relay.RelayData,Port5-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"----->"); //port 5 on
  else if (bitRead(ReefAngel.Relay.RelayData,Port6-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"<-----"); //port 6 on
  else ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67," 00000 "); //port5 and port 6 off, wavemaker delay
  //show the timer for wavemaker
  int t=ReefAngel.Timer[1].Trigger-now();
  if (t>=0)
    ReefAngel.LCD.Clear(255,105,64,135,74);
  ReefAngel.LCD.DrawText(APColor, COLOR_KHAKI,105,64,t);
  pingSerial();

  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
  // ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
  ReefAngel.Init(); //Initialize controller
  ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));

  ReefAngel.FeedingModePorts = Port2Bit | Port5Bit | Port6Bit;
  ReefAngel.WaterChangePorts = Port2Bit | Port5Bit | Port6Bit | Port8Bit;
  ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit | Port7Bit;
  ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
  randomSeed(analogRead(0));
  ReefAngel.Timer[1].SetInterval(random(30,45));
  ReefAngel.Timer[1].Start(); 
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  InternalMemory.OverheatTemp_write( 805 );
  ReefAngel.Relay.On(Port5);
  ReefAngel.Relay.On(Port2);
  ReefAngel.Relay.On(Port8);
}

void loop()
{
  // Specific functions
  ReefAngel.StandardATO(Port1,240);
  ReefAngel.StandardLights(Port3,10,0,22,0);
  ReefAngel.StandardLights(Port4,11,0,21,0);
  ReefAngel.StandardHeater(Port7,770,790);

  //wavemaker timers and slow down at night
  if ( ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(60); // wm night delay
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        ReefAngel.Timer[1].SetInterval(20); // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-9p normal wave settings
      ReefAngel.Timer[1].SetInterval(random(35,50));
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      if bitRead(ReefAngel.Relay.RelayData,Port5-1) ReefAngel.Relay.Off(Port6); 
      else ReefAngel.Relay.On(Port6);
    }
  }
  ReefAngel.Portal("dtzreef");
  ReefAngel.ShowInterface();
}


Roberto.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

BAM!!! You are great!!!
Except, the Lights On/Off doesn't work and the Skimmer (port #2) does not turn back on after waterchange mode.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

Controller is showing port #2 on. But it is not.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

Check last!!!! Skimmer does work, it was the pump......duh
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Adding to code

Post by rimai »

I tested the code and I can make port 3 and 4 turn on when you choose lights on and they turn off when you hit lights off.
Roberto.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

Ok. I'll give it another try in the morning. What part in the code controls the lights on/off? I really want to learn to code it myself someday. Thanks again
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Adding to code

Post by rimai »

Code: Select all

void MenuEntry6()
{
  ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
#ifdef RelayExp
  for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
  {
    ReefAngel.Relay.RelayMaskOnE[i] = ReefAngel.LightsOnPortsE[i];
  }
#endif  // RelayExp
  ReefAngel.Relay.Write();
}

void MenuEntry7()
{
  ReefAngel.Relay.RelayMaskOn = 0;
#ifdef RelayExp
  for ( byte i = 0; i < MAX_RELAY_EXPANSION_MODULES; i++ )
  {
    ReefAngel.Relay.RelayMaskOnE[i] = 0;
  }
#endif  // RelayExp
  ReefAngel.Relay.Write();
}
Roberto.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

Got it. Worked from the beginning, it just doesn't turn the lights off when they are on during the day, just on/ off at night. Can lights on/ off during the day be coded as well? I hope this makes sense.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Adding to code

Post by rimai »

Try this one:

Code: Select all

#include <ReefAngel_Features.h>
#include <RA_Colors.h>
#include <RA_CustomColors.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_Colors.h>
#include <RA_CustomColors.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 <ReefAngel.h>

byte wmport=Port5;
boolean wmdelay=false;


#include <avr/pgmspace.h>
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "ATO Clear";
prog_char menu4_label[] PROGMEM = "Overheat Clear";
prog_char menu5_label[] PROGMEM = "PH Calibration";
prog_char menu6_label[] PROGMEM = "Lights On";
prog_char menu7_label[] PROGMEM = "Lights Off";
prog_char menu8_label[] PROGMEM = "Lights Auto";
prog_char menu9_label[] PROGMEM = "Date/Time";

PROGMEM const char *menu_items[] = {
  menu1_label, menu2_label, menu3_label, menu4_label, menu5_label, menu6_label, menu7_label, menu8_label, menu9_label  };

void MenuEntry1()
{
  ReefAngel.FeedingModeStart();

}
void MenuEntry2()
{
  ReefAngel.WaterChangeModeStart();

}
void MenuEntry3()
{
  ReefAngel.ATOClear();
  ReefAngel.DisplayMenuEntry("Clear ATO Timeout");
}
void MenuEntry4()
{
  ReefAngel.OverheatClear();
  ReefAngel.DisplayMenuEntry("Clear Overheat");
}
void MenuEntry5()
{
  ReefAngel.SetupCalibratePH();
  ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;

}

void MenuEntry6()
{
  ReefAngel.Relay.RelayMaskOn = ReefAngel.LightsOnPorts;
  ReefAngel.Relay.RelayMaskOff = 255;
  ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}

void MenuEntry7()
{
  ReefAngel.Relay.RelayMaskOn = 0;
  ReefAngel.Relay.RelayMaskOff = ~ReefAngel.LightsOnPorts;
  ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}

void MenuEntry8()
{
  ReefAngel.Relay.RelayMaskOn = 0;
  ReefAngel.Relay.RelayMaskOff = 255;
  ReefAngel.DisplayedMenu=RETURN_MAIN_MODE;
}

void MenuEntry9()
{
  ReefAngel.SetupDateTime();
  ReefAngel.DisplayedMenu = ALT_SCREEN_MODE;
}





void DrawCustomMain()
{

  ReefAngel.LCD.DrawDate(6, 120);
  ReefAngel.LCD.DrawLargeText(COLOR_DARKTURQUOISE, COLOR_WHITE, 4, 4 , "DTZ REEF ANGEL");
  ReefAngel.LCD.Clear(COLOR_MAROON, 1, 13, 132, 13);
  ReefAngel.LCD.Clear(COLOR_MAROON, 10, 75, 119, 75);
  ReefAngel.LCD.Clear(COLOR_MAROON, 10, 118, 119, 118);
  pingSerial();


  ReefAngel.LCD.DrawText(COLOR_GOLDENROD, COLOR_WHITE, 8, 15, "Main Tank:");
  char text[7];
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  pingSerial();
  ReefAngel.LCD.DrawText(COLOR_GOLDENROD, DefaultBGColor, 88, 15, text);
  pingSerial(); 

  ReefAngel.LCD.DrawText(COLOR_MEDIUMSEAGREEN, COLOR_WHITE, 50, 46, "pH:");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);

  ReefAngel.LCD.DrawText(PHColor, DefaultBGColor, 88, 46, text);
  pingSerial();

  ReefAngel.LCD.DrawText(COLOR_RED, COLOR_WHITE,8,25,"Room Temp:");
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T3_PROBE], COLOR_RED, 88, 25, 10);

  ReefAngel.LCD.DrawText(COLOR_DARKORCHID, COLOR_WHITE,8,36,"Refugium:");
  ReefAngel.LCD.DrawSingleMonitor(ReefAngel.Params.Temp[T2_PROBE], T2TempColor, 88, 36, 10);

  pingSerial();
  // Display arrows for Wavemaker
  ReefAngel.LCD.DrawText(DPColor,DefaultBGColor, 38, 57,"WAVE FLOW:");
  if (bitRead(ReefAngel.Relay.RelayData,Port5-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"----->"); //port 5 on
  else if (bitRead(ReefAngel.Relay.RelayData,Port6-1)==1) ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67,"<-----"); //port 6 on
  else ReefAngel.LCD.DrawText(APColor,DefaultBGColor, 49, 67," 00000 "); //port5 and port 6 off, wavemaker delay
  //show the timer for wavemaker
  int t=ReefAngel.Timer[1].Trigger-now();
  if (t>=0)
    ReefAngel.LCD.Clear(255,105,64,135,74);
  ReefAngel.LCD.DrawText(APColor, COLOR_KHAKI,105,64,t);
  pingSerial();

  byte TempRelay = ReefAngel.Relay.RelayData;
  TempRelay &= ReefAngel.Relay.RelayMaskOff;
  TempRelay |= ReefAngel.Relay.RelayMaskOn;
  ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

void DrawCustomGraph()
{
  // ReefAngel.LCD.DrawGraph(5, 5);
}


void setup()
{
  ReefAngel.Init(); //Initialize controller
  ReefAngel.InitMenu(pgm_read_word(&(menu_items[0])),SIZE(menu_items));

  ReefAngel.FeedingModePorts = Port2Bit | Port5Bit | Port6Bit;
  ReefAngel.WaterChangePorts = Port2Bit | Port5Bit | Port6Bit | Port8Bit;
  ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit | Port7Bit;
  ReefAngel.LightsOnPorts = Port3Bit | Port4Bit;
  randomSeed(analogRead(0));
  ReefAngel.Timer[1].SetInterval(random(30,45));
  ReefAngel.Timer[1].Start(); 
  ReefAngel.TempProbe = T1_PROBE;
  ReefAngel.OverheatProbe = T1_PROBE;
  InternalMemory.OverheatTemp_write( 805 );
  ReefAngel.Relay.On(Port5);
  ReefAngel.Relay.On(Port2);
  ReefAngel.Relay.On(Port8);
}

void loop()
{
  // Specific functions
  ReefAngel.StandardATO(Port1,240);
  ReefAngel.StandardLights(Port3,10,0,22,0);
  ReefAngel.StandardLights(Port4,11,0,21,0);
  ReefAngel.StandardHeater(Port7,770,790);

  //wavemaker timers and slow down at night
  if ( ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-8a 
    {
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(60); // wm night delay
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; 
        else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        ReefAngel.Timer[1].SetInterval(20); // short wave
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-9p normal wave settings
      ReefAngel.Timer[1].SetInterval(random(35,50));
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      if bitRead(ReefAngel.Relay.RelayData,Port5-1) ReefAngel.Relay.Off(Port6); 
      else ReefAngel.Relay.On(Port6);
    }
  }
  ReefAngel.Portal("dtzreef");
  ReefAngel.ShowInterface();
}


Roberto.
dtzreef
Posts: 50
Joined: Sat Jul 14, 2012 8:58 pm

Re: Adding to code

Post by dtzreef »

Thanks so much Roberto!! Now, is there a code to have it make breakfast in the morning;)
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Adding to code

Post by lnevo »

You could use an expansion relay box to turn on the coffee machine and the toaster...
Post Reply