Page 1 of 1

custom code errors

Posted: Sat Feb 07, 2015 8:22 am
by jjdezek
I just got a second dosing pump and was going to set it up. when I tried to load my code it gave me an error, so I ran my last code that I have currently set up on my system and it also gave me an error yet it is currently running my system. when I run just he basic wizard set up it runs fine without errors. I have a custom screen code that seems to be causing the errors ( I think) that never occurred before. did something change with the software that would stop me from using my current custom screen coding?
#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
#define NUMBERS_8x16
void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.DrawDate(6, 112);
ReefAngel.LCD.DrawText(COLOR_INDIGO, COLOR_WHITE,25,5, "Jeremy's Reef");
pingSerial();

DrawStatus (20,80);
DrawParams (5,40);
DrawParamsa (0,10);
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

////// 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 = Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T3_PROBE;
    ReefAngel.OverheatProbe = T3_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );

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


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

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

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

void loop()
{
    ReefAngel.StandardATO( Port1,20 );
    ReefAngel.StandardLights( Port3,18,0,10,0 );
    ReefAngel.StandardHeater( Port7);
    ReefAngel.PWM.SetChannel( 0, PWMSlope(7,0,21,0,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(7,5,21,5,5,45,180,5) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(7,10,21,10,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(7,15,21,15,5,45,180,5) );
    ReefAngel.PWM.SetChannel( 4, PWMSlope(7,20,21,20,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 5, PWMSlope(7,25,21,25,5,45,180,5) );
    ReefAngel.DCPump.DaylightChannel = AntiSync;
    ReefAngel.DCPump.ActinicChannel = Sync;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
      if (ReefAngel.DCPump.Mode==Custom)
  {
  ReefAngel.PWM.SetDaylight( ElseMode(70,30,true )); // ElseMode on sync mode, 70 +/- 30%
  ReefAngel.PWM.SetActinic( ElseMode(70,30,false )); // ElseMode on anti-sync mode, 70 +/- 30%
  }


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

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

void DrawParamsa(int x, int y){
char buf[16];
  ReefAngel.LCD.DrawText(DPColor,DefaultBGColor,x+70,y+10,"WP40L:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(), DPColor, x+108, y+10,1);
ReefAngel.LCD.DrawText(APColor,DefaultBGColor,x+70,y+20,"WP40R:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(),APColor, x+108, y+20,1);

}

void DrawParams(int x, int y) {
  char buf[16];

  ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x+5,y,"Temp:");
  ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x+80, y, "PH:");
  // Temp and PH
  y+=10;

  ConvertNumToString(buf, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T1TempColor, DefaultBGColor, x+5, y, buf, Num8x16);
    ConvertNumToString(buf, ReefAngel.Params.Temp[T2_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T2TempColor, DefaultBGColor, x+5, y+12, buf, Num8x16);
    ConvertNumToString(buf, ReefAngel.Params.Temp[T3_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T3TempColor, DefaultBGColor, x+40, y+12, buf, Num8x16);
  ConvertNumToString(buf, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(PHColor, DefaultBGColor, x+80, y, buf, Num8x16);
  y+=5;
   ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,10,18, "SAL:" );
    ReefAngel.LCD.DrawSingleMonitor( ReefAngel.Params.Salinity,COLOR_DARKKHAKI,33,18, 10 );
}

void DrawStatus(int x, int y) {
  int t=x;
  
  ReefAngel.LCD.DrawLargeText(COLOR_INDIGO,DefaultBGColor,15,y,"High",Font8x16);
  ReefAngel.LCD.DrawLargeText(COLOR_INDIGO,DefaultBGColor,85,y,"Low",Font8x16);
  
  if (ReefAngel.HighATO.IsActive()) {
    ReefAngel.LCD.FillCircle(55,y+3,5,COLOR_GREEN);
  } else {
    ReefAngel.LCD.FillCircle(55,y+3,5,COLOR_RED);
  }
  
  if (ReefAngel.LowATO.IsActive()) {
    ReefAngel.LCD.FillCircle(70,y+3,5,COLOR_GREEN);
  } else {
    ReefAngel.LCD.FillCircle(70,y+3,5,COLOR_RED);
  }
}

void DrawCustomGraph()
{
}

byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000); // Set the initial delay
  static int NewSpeed = MidPoint; // Set the initial speed
  static int AntiSpeed = MidPoint; // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
  {
    Delay=random(500,5000); // If so, come up with a new delay
    int ChangeUp = random(Offset); // Amount to go up or down
    if (random(100)<50) // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis(); // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}

Re: custom code errors

Posted: Sat Feb 07, 2015 9:04 am
by lnevo
Take out the ElseMode function at the bottom. It's in the libraries now. If still getting errors post the error your getting

Re: custom code errors

Posted: Sat Feb 07, 2015 10:39 am
by jjdezek
which else mode part are you talking about?
this is the code im trying to load
#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
#define NUMBERS_8x16
void DrawCustomMain()
{
// the graph is drawn/updated when we exit the main menu &
// when the parameters are saved
ReefAngel.LCD.DrawDate(6, 112);
ReefAngel.LCD.DrawText(COLOR_INDIGO, COLOR_WHITE,25,5, "Jeremy's Reef");
pingSerial();

DrawStatus (20,80);
DrawParams (5,40);
DrawParamsa (0,10);
pingSerial();
byte TempRelay = ReefAngel.Relay.RelayData;
TempRelay &= ReefAngel.Relay.RelayMaskOff;
TempRelay |= ReefAngel.Relay.RelayMaskOn;
ReefAngel.LCD.DrawOutletBox(12, 93, TempRelay);
}

////// 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 = Port5Bit | Port6Bit | Port8Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = 0;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T3_PROBE;
    ReefAngel.OverheatProbe = T3_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 820 );

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


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

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

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

void loop()
{
    ReefAngel.StandardATO( Port1,30 );
    ReefAngel.DosingPumpRepeat( Port3,15,360,2 );
    ReefAngel.DosingPumpRepeat( Port4,15,360,5 );
    ReefAngel.StandardHeater( Port7,770,775 );
    ReefAngel.PWM.SetChannel( 0, PWMSlope(7,0,21,0,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 1, PWMSlope(7,5,21,5,5,45,180,5) );
    ReefAngel.PWM.SetChannel( 2, PWMSlope(7,10,21,10,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 3, PWMSlope(7,15,21,15,5,45,180,5) );
    ReefAngel.PWM.SetChannel( 4, PWMSlope(7,20,21,20,5,55,180,5) );
    ReefAngel.PWM.SetChannel( 5, PWMSlope(7,25,21,25,5,45,180,5) );
    ReefAngel.DCPump.DaylightChannel = AntiSync;
    ReefAngel.DCPump.ActinicChannel = Sync;
    ReefAngel.DCPump.ExpansionChannel[0] = None;
    ReefAngel.DCPump.ExpansionChannel[1] = None;
    ReefAngel.DCPump.ExpansionChannel[2] = None;
    ReefAngel.DCPump.ExpansionChannel[3] = None;
    ReefAngel.DCPump.ExpansionChannel[4] = None;
    ReefAngel.DCPump.ExpansionChannel[5] = None;
    ////// Place your custom code below here
      if (ReefAngel.DCPump.Mode==Custom)
  {
  ReefAngel.PWM.SetDaylight( ElseMode(70,30,true )); // ElseMode on sync mode, 70 +/- 30%
  ReefAngel.PWM.SetActinic( ElseMode(70,30,false )); // ElseMode on anti-sync mode, 70 +/- 30%
  }


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

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

void DrawParamsa(int x, int y){
char buf[16];
  ReefAngel.LCD.DrawText(DPColor,DefaultBGColor,x+70,y+10,"WP40L:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetDaylightValue(), DPColor, x+108, y+10,1);
ReefAngel.LCD.DrawText(APColor,DefaultBGColor,x+70,y+20,"WP40R:");
ReefAngel.LCD.DrawSingleMonitor(ReefAngel.PWM.GetActinicValue(),APColor, x+108, y+20,1);

}

void DrawParams(int x, int y) {
  char buf[16];

  ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x+5,y,"Temp:");
  ReefAngel.LCD.DrawText(COLOR_BLACK,DefaultBGColor,x+80, y, "PH:");
  // Temp and PH
  y+=10;

  ConvertNumToString(buf, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T1TempColor, DefaultBGColor, x+5, y, buf, Num8x16);
    ConvertNumToString(buf, ReefAngel.Params.Temp[T2_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T2TempColor, DefaultBGColor, x+5, y+12, buf, Num8x16);
    ConvertNumToString(buf, ReefAngel.Params.Temp[T3_PROBE], 10);
  ReefAngel.LCD.DrawLargeText(T3TempColor, DefaultBGColor, x+40, y+12, buf, Num8x16);
  ConvertNumToString(buf, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(PHColor, DefaultBGColor, x+80, y, buf, Num8x16);
  y+=5;
   ReefAngel.LCD.DrawText( COLOR_DARKKHAKI,DefaultBGColor,10,18, "SAL:" );
    ReefAngel.LCD.DrawSingleMonitor( ReefAngel.Params.Salinity,COLOR_DARKKHAKI,33,18, 10 );
}

void DrawStatus(int x, int y) {
  int t=x;
  
  ReefAngel.LCD.DrawLargeText(COLOR_INDIGO,DefaultBGColor,15,y,"High",Font8x16);
  ReefAngel.LCD.DrawLargeText(COLOR_INDIGO,DefaultBGColor,85,y,"Low",Font8x16);
  
  if (ReefAngel.HighATO.IsActive()) {
    ReefAngel.LCD.FillCircle(55,y+3,5,COLOR_GREEN);
  } else {
    ReefAngel.LCD.FillCircle(55,y+3,5,COLOR_RED);
  }
  
  if (ReefAngel.LowATO.IsActive()) {
    ReefAngel.LCD.FillCircle(70,y+3,5,COLOR_GREEN);
  } else {
    ReefAngel.LCD.FillCircle(70,y+3,5,COLOR_RED);
  }
}

void DrawCustomGraph()
{
}

byte ElseMode( byte MidPoint, byte Offset, boolean WaveSync )
{
  // Static's only initialize the first time they are called
  static unsigned long LastChange=millis(); // Set the inital time that the last change occurred
  static int Delay = random( 500, 3000); // Set the initial delay
  static int NewSpeed = MidPoint; // Set the initial speed
  static int AntiSpeed = MidPoint; // Set the initial anti sync speed
  if ((millis()-LastChange) > Delay) // Check if the delay has elapsed
  {
    Delay=random(500,5000); // If so, come up with a new delay
    int ChangeUp = random(Offset); // Amount to go up or down
    if (random(100)<50) // 50/50 chance of speed going up or going down
    {
      NewSpeed = MidPoint - ChangeUp;
      AntiSpeed = MidPoint + ChangeUp;
    }
    else
    {
      NewSpeed = MidPoint + ChangeUp;
      AntiSpeed = MidPoint - ChangeUp;
    }
    LastChange=millis(); // Reset the time of the last change
  }
  if (WaveSync)
  {
    return NewSpeed;
  }
  else
  {
    return AntiSpeed;
  }
}
this is the error I get

The following features were detected:
Dimming Expansion Module
Dimming Signal
Salinity Expansion Module
Wifi Attachment
Custom Main Screen
Extra Font - Medium Size (8x8 pixels)
Extra Font - Numbers Only - Large Font (8x16 pixels)
DC Pump Control (Jebao/Tunze)
Simple Menu
Globals\Globals.cpp.o: In function `ElseMode(unsigned char, unsigned char, unsigned char)':
C:\Users\christina\Documents\Arduino\libraries\Globals/Globals.cpp:881: multiple definition of `ElseMode(unsigned char, unsigned char, unsigned char)'
sketch_07FEB15.cpp.o:C:\Users\CHRIST~1\AppData\Local\Temp\build5625720558528318428.tmp/sketch_07FEB15.cpp:187: first defined here
c:/program files (x86)/reef angel controller/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

Re: custom code errors

Posted: Sat Feb 07, 2015 10:58 am
by rimai
There is an entire ElseMode function at the end of your code.
That entire function is now part of the libraries. You should remove it from your code or it will complain about being duplicated.

Re: custom code errors

Posted: Sat Feb 07, 2015 11:02 am
by jjdezek
is this what your talking about?
{
ReefAngel.PWM.SetDaylight( ElseMode(70,30,true )); // ElseMode on sync mode, 70 +/- 30%
ReefAngel.PWM.SetActinic( ElseMode(70,30,false )); // ElseMode on anti-sync mode, 70 +/- 30%
}
or should I remove everything in the code that says else?

Re: custom code errors

Posted: Sat Feb 07, 2015 11:07 am
by rimai
At the very end of your code.
The entire ElseMode function

Re: custom code errors

Posted: Sat Feb 07, 2015 11:10 am
by jjdezek
ok got it. will my jeabos still function without that code? or was that competing against another code for controlling them?

Re: custom code errors

Posted: Sat Feb 07, 2015 11:20 am
by rimai
Yes, they will. Like we said before, it has been added as part of the libraries and you don't need to explicit declare it in your code anymore.
Our libraries is ever evolving and codes that people use, try it and like it becomes eventually part of the libraries, so it makes it easy for everyone to use without having to add additional stuff to their code.
This is a example of such thing.
A user created this ElseMode function that has been adopted by several users and everyone liked. I went ahead and made it integral part of the libraries so everyone can use it too without having to add anything to their code and the Wizard is now capable of setting the DC Pumps to Else mode :)

Re: custom code errors

Posted: Sat Feb 07, 2015 11:30 am
by jjdezek
Ok well I loaded the code without the else mode in there but my one jeabo is only pushing at 30% and the other one is off

Re: custom code errors

Posted: Sat Feb 07, 2015 11:38 am
by rimai
According to your code, you didn't set any mode to your DC Pumps.
I recommend you updating your code to utilize the new libraries and remove the PWM class you are using now.
Change this:

Code: Select all

      if (ReefAngel.DCPump.Mode==Custom)
  {
  ReefAngel.PWM.SetDaylight( ElseMode(70,30,true )); // ElseMode on sync mode, 70 +/- 30%
  ReefAngel.PWM.SetActinic( ElseMode(70,30,false )); // ElseMode on anti-sync mode, 70 +/- 30%
  }
To this:

Code: Select all

    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.SetMode( Else,70,30 );
Or to this if you want to control from phone app or portal:

Code: Select all

    ReefAngel.DCPump.UseMemory = true;