Help with code

Do you have a question on how to do something.
Ask in here.
Post Reply
Spotted
Posts: 101
Joined: Thu May 10, 2012 5:46 am
Location: Sunny (and hot) South Florida

Help with code

Post by Spotted »

Here's my code

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


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Box1_Port2 );

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

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

void loop()
{
    ReefAngel.SingleATO( true,Port1,120,10 );
    ReefAngel.StandardLights( Port2,19,0,7,0 );
    ReefAngel.StandardLights( Port4,10,0,20,0 );
    ReefAngel.StandardLights( Port5,6,0,22,0 );
    ReefAngel.StandardHeater( Port6,780,805 );
    ReefAngel.Relay.DelayedOn( Port7,5 );
    ReefAngel.Relay.DelayedOn( Port8,3 );
    ReefAngel.DosingPumpRepeat( Box1_Port3,0,60,170 );
    ReefAngel.StandardLights( Box1_Port7,13,0,17,0 );
    ReefAngel.StandardLights( Box1_Port8,12,0,18,0 );
    ReefAngel.PWM.SetDaylight( PWMParabola(13,0,16,0,10,80,10) );
    ReefAngel.PWM.SetActinic( PWMSlope(10,0,18,0,15,95,80,15) );
    ////// Place your custom code below here
#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 
    // Ports toggled in Feeding Mode
    ReefAngel.FeedingModePorts = Port1Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.FeedingModePortsE[0] = Port1Bit | Port2Bit | Port3Bit;
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = Port1Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.WaterChangePortsE[0] = Port1Bit | Port2Bit | Port3Bit;
    // Ports toggled when Lights On / Off menu entry selected
    ReefAngel.LightsOnPorts = Port2Bit | Port4Bit;
    ReefAngel.LightsOnPortsE[0] = Port7Bit | Port8Bit;
    // Ports turned off when Overheat temperature exceeded
    ReefAngel.OverheatShutoffPorts = Port3Bit | Port4Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port1Bit | Port2Bit | Port7Bit;
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;
    // Set the Overheat temperature setting
    InternalMemory.OverheatTemp_write( 815 );


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Box1_Port2 );

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

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

void loop()
{
    ReefAngel.SingleATO( true,Port1,120,10 );
    ReefAngel.StandardLights( Port2,19,0,7,0 );
    ReefAngel.StandardLights( Port4,10,0,20,0 );
    ReefAngel.StandardLights( Port5,6,0,22,0 );
    ReefAngel.StandardHeater( Port6,780,805 );
    ReefAngel.Relay.DelayedOn( Port7,5 );
    ReefAngel.Relay.DelayedOn( Port8,3 );
    ReefAngel.DosingPumpRepeat( Box1_Port3,0,60,170 );
    ReefAngel.StandardLights( Box1_Port7,13,0,17,0 );
    ReefAngel.StandardLights( Box1_Port8,12,0,18,0 );
    ReefAngel.PWM.SetDaylight( PWMParabola(13,0,16,0,10,80,10) );
    ReefAngel.PWM.SetActinic( PWMSlope(10,0,18,0,15,95,80,15) );
    ////// Place your custom code below here
    if ((now()%SECS_PER_DAY==28800)) //if it is 8 AM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
    if ((now()%SECS_PER_DAY==64800)) //if it is 6 PM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
    ////// Place your custom code above here

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



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

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


I'm getting the following errors when I try to compile it. What is wrong with it?

The following features were detected:
Dimming Signal
Wifi Attachment
Relay Expansion Module
2014 Main Screen
Extra Font - Medium Size (8x8 pixels)
Number of Relay Expansion Modules: 1
Simple Menu
sketch_jan21a.cpp: In function 'void loop()':
sketch_jan21a:124: error: a function-definition is not allowed here before '{' token
sketch_jan21a:158: error: a function-definition is not allowed here before '{' token
sketch_jan21a:190: error: expected `}' at end of input
Binary sketch size: 56,450 bytes (of a 258,048 byte maximum)


Thanks Guys!!
:cry:
Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Help with code

Post by Sacohen »

There may be more reasons, but from what I see you have the following in two places...

#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>

First where it should be at the very beginning before ////// Place global variable code below here

The 2nd time is after ////// Place your custom code below here.

Remove it from after ////// Place your custom code below here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Help with code

Post by Sacohen »

I looked at it more and you definitely had a bunch of items duplicated.

Try this code.
It compiled for me just fine.

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


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Box1_Port2 );

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

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

void loop()
{
    ReefAngel.SingleATO( true,Port1,120,10 );
    ReefAngel.StandardLights( Port2,19,0,7,0 );
    ReefAngel.StandardLights( Port4,10,0,20,0 );
    ReefAngel.StandardLights( Port5,6,0,22,0 );
    ReefAngel.StandardHeater( Port6,780,805 );
    ReefAngel.Relay.DelayedOn( Port7,5 );
    ReefAngel.Relay.DelayedOn( Port8,3 );
    ReefAngel.DosingPumpRepeat( Box1_Port3,0,60,170 );
    ReefAngel.StandardLights( Box1_Port7,13,0,17,0 );
    ReefAngel.StandardLights( Box1_Port8,12,0,18,0 );
    ReefAngel.PWM.SetDaylight( PWMParabola(13,0,16,0,10,80,10) );
    ReefAngel.PWM.SetActinic( PWMSlope(10,0,18,0,15,95,80,15) );
    ////// Place your custom code below here

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


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


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

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




Spotted
Posts: 101
Joined: Thu May 10, 2012 5:46 am
Location: Sunny (and hot) South Florida

Re: Help with code

Post by Spotted »

I'm sorry, this is the code that should have gotten posted the first time.

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


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Box1_Port2 );

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

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

void loop()
{
    ReefAngel.SingleATO( true,Port1,120,10 );
    ReefAngel.StandardLights( Port2,19,0,7,0 );
    ReefAngel.StandardLights( Port4,10,0,20,0 );
    ReefAngel.StandardLights( Port5,6,0,22,0 );
    ReefAngel.StandardHeater( Port6,780,805 );
    ReefAngel.Relay.DelayedOn( Port7,5 );
    ReefAngel.Relay.DelayedOn( Port8,3 );
    ReefAngel.DosingPumpRepeat( Box1_Port3,0,60,170 );
    ReefAngel.StandardLights( Box1_Port7,13,0,17,0 );
    ReefAngel.StandardLights( Box1_Port8,12,0,18,0 );
    ReefAngel.PWM.SetDaylight( PWMParabola(13,0,16,0,10,80,10) );
    ReefAngel.PWM.SetActinic( PWMSlope(10,0,18,0,15,95,80,15) );
    ////// Place your custom code below here

     if ((now()%SECS_PER_DAY==28800)) //if it is 8 AM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
    if ((now()%SECS_PER_DAY==64800)) //if it is 6 PM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
    ////// Place your custom code above here

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

What i am trying to do is to get my RA to start feed mode automatically at 8 AM and 6 PM.
Image
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Help with code

Post by cosmith71 »

This should do it.

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


    // Ports that are always on
    ReefAngel.Relay.On( Port3 );
    ReefAngel.Relay.On( Box1_Port2 );

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

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

void loop()
{
    ReefAngel.SingleATO( true,Port1,120,10 );
    ReefAngel.StandardLights( Port2,19,0,7,0 );
    ReefAngel.StandardLights( Port4,10,0,20,0 );
    ReefAngel.StandardLights( Port5,6,0,22,0 );
    ReefAngel.StandardHeater( Port6,780,805 );
    ReefAngel.Relay.DelayedOn( Port7,5 );
    ReefAngel.Relay.DelayedOn( Port8,3 );
    ReefAngel.DosingPumpRepeat( Box1_Port3,0,60,170 );
    ReefAngel.StandardLights( Box1_Port7,13,0,17,0 );
    ReefAngel.StandardLights( Box1_Port8,12,0,18,0 );
    ReefAngel.PWM.SetDaylight( PWMParabola(13,0,16,0,10,80,10) );
    ReefAngel.PWM.SetActinic( PWMSlope(10,0,18,0,15,95,80,15) );
    ////// Place your custom code below here

    if(hour()==8 && minute()==0 && second()==0) ReefAngel.FeedingModeStart();  // Feeding mode at 0800
    if(hour()==18 && minute()==0 && second()==0) ReefAngel.FeedingModeStart(); // Feeding mode at 1800
    
    ////// Place your custom code above here

    // This should always be the last line
    ReefAngel.Portal( "Spotted" );
    ReefAngel.ShowInterface();
}
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Help with code

Post by cosmith71 »

Your original code would work also, but you put the } after the // comment. Everything on the line after // gets ignored.

Code: Select all

 if ((now()%SECS_PER_DAY==28800)) //if it is 8 AM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
    if ((now()%SECS_PER_DAY==64800)) //if it is 6 PM
    {ReefAngel.FeedingModeStart(); //START FEEDING MODE}
Should be:

Code: Select all

 if ((now()%SECS_PER_DAY==28800)) //if it is 8 AM
    {ReefAngel.FeedingModeStart();} //START FEEDING MODE
    if ((now()%SECS_PER_DAY==64800)) //if it is 6 PM
    {ReefAngel.FeedingModeStart();} //START FEEDING MODE
Post Reply