Lights on mode isn't working.

Do you have a question on how to do something.
Ask in here.
Post Reply
GugsJr
Posts: 68
Joined: Fri Jun 20, 2014 6:30 am

Lights on mode isn't working.

Post by GugsJr »

I need help with a certain part of my code and the lights.

Since my LEDs dim to 0 when I use lights on it doesn't work with my current code. I can get the lights to come on but not go back to 0 after I use lights off.

Current 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 <PAR.h>
#include <ReefAngel.h>

// Define Relay Ports by Name

#define Feeder             Port6


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


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


void setup()
{
    // This must be the first line
    ReefAngel.Init();  //Initialize controller
      
    // Feeeding and Water Change mode speed
    ReefAngel.DCPump.FeedingSpeed=0;
    ReefAngel.DCPump.WaterChangeSpeed=0;
    ReefAngel.DCPump.ActinicChannel=Sync; // Now you're pump will be affected by the portal settings.
    ReefAngel.DCPump.DaylightChannel=AntiSync; // Now you're pump will be affected by the portal settings.
    ReefAngel.DCPump.Threshold=30; //Jebao won't go over 30%
   
    // Ports toggled in Water Change Mode
    ReefAngel.WaterChangePorts = 0;
    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 = Port5Bit;
    ReefAngel.OverheatShutoffPortsE[0] = Port3Bit | Port5Bit;
   
    // Use T1 probe as temperature and overheat functions
    ReefAngel.TempProbe = T1_PROBE;
    ReefAngel.OverheatProbe = T1_PROBE;

   


    // Ports that are always on
    ReefAngel.Relay.On( Port7 );
    ReefAngel.Relay.On( Port8 );
    ReefAngel.Relay.On( Box1_Port1 );
    ReefAngel.Relay.On( Box1_Port2 );
    ReefAngel.Relay.On( Box1_Port8 );

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


    

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

void loop()
{

// seasonal temperatures
    SeasonalTemps();

    ReefAngel.StandardLights( Port1,14,25,1,5 );
    ReefAngel.StandardLights( Port2,14,25,3,10 );
    ReefAngel.StandardLights( Port3,22,55,2,30 );
    ReefAngel.StandardLights( Port4,23,55,3,0 );
    ReefAngel.PWM.Channel1PWMParabola(); //Front Whites 4:00pm-10:00pm
    ReefAngel.PWM.Channel2PWMParabola(90); //Back Blues 2:30pm-11:30pm
    ReefAngel.PWM.Channel3PWMParabola(-30,30); //Back Whites 4:30pm-10:30pm
    ReefAngel.PWM.Channel4PWMParabola(120); //Back Blues 3:00pm-12:00AM
    ReefAngel.StandardATO( Box1_Port6 );
    ReefAngel.StandardLights( Box1_Port7,22,0,17,0 );
    ReefAngel.DCPump.UseMemory = false;
    ReefAngel.DCPump.DaylightChannel = Sync;
    ReefAngel.DCPump.ActinicChannel = AntiSync;
    ReefAngel.DCPump.ExpansionChannel[0] = Sync;
    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

//AutoFeeder
static unsigned long autofeeding = 0;

if (hour()==17 && minute()==0 && second() <= 2)//if it is 5 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( autofeeding == 0 ) {
autofeeding = now(); //set the time of the start of feeding to variable feeding
}

if ((now()-autofeeding>=60) && (now()-autofeeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Feeder); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Feeder); //TURN FEEDER RELAY OFF
}
} else {
if ( autofeeding > 0 ) {
autofeeding = 0;
}
} 

// Add random mode if we set to Mode to Custom in portal
static int rmode;
static boolean changeMode=true;


// These are the modes we can cycle through. You can add more and even repeat...
byte modes[] = { ReefCrest, Gyre, Lagoon, Constant, TidalSwell, ShortPulse, LongPulse, Else, };

if (now()%SECS_PER_DAY==0 || changeMode==true) { // Change at midnight or if controller rebooted
rmode=random(100)%sizeof(modes); // Change the mode once per day to pick from our array
changeMode=false;
}

// Set timer when in feeding mode
static unsigned long feeding;
if (ReefAngel.DisplayedMenu==FEEDING_MODE) feeding=now();

if (now()-feeding<9000) { 
  // Continue NTM for the 2 hours 30 minutes
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=NutrientTransport;
} else if (now()%SECS_PER_DAY<1800 || now()%SECS_PER_DAY>=52200) { // 12:30am / 2:30pm
  // Night mode (go to 15%)
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=Lagoon;
  ReefAngel.DCPump.Speed=15;
} else if (InternalMemory.DCPumpMode_read()==11) { 
  // Custom Mode and nothing else going on
  ReefAngel.DCPump.UseMemory=false;
  ReefAngel.DCPump.Duration=InternalMemory.DCPumpDuration_read();
  ReefAngel.DCPump.Mode=modes[rmode];  // Put the mode to the random mode :)
  ReefAngel.DCPump.Speed=InternalMemory.DCPumpSpeed_read(); // Set speed from portal
} else {
  ReefAngel.DCPump.UseMemory=true; // Will reset all values from memory
}
    

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

    // This should always be the last line
    ReefAngel.Portal( "GugsJr" );
    ReefAngel.DDNS( "Home" ); // Your DDNS is GugsJr-Home.myreefangel.com
    ReefAngel.ShowInterface();
}

//Custom Main, Graph & Menu

void DrawCustomMain() {
  byte x = 6;
  byte y = 2;
  byte t;
  char text[7];

 ReefAngel.LCD.DrawLargeText(COLOR_WHITE, COLOR_BLACK, 6, 2, "GugsJr’s ReefAngel");
 ReefAngel.LCD.DrawDate(6, 118);
 ReefAngel.LCD.Clear(COLOR_BLACK, 1, 17, 132, 17);
 pingSerial();

  ReefAngel.LCD.DrawLargeText(0,255,10,16,"  Jebao Mode:");
  if (ReefAngel.DCPump.Mode == 0) ReefAngel.LCD.DrawLargeText(COLOR_LIMEGREEN,255,35,27,"Constant");
  else if(ReefAngel.DCPump.Mode == 1) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,42,26,"Lagoon");
  else if (ReefAngel.DCPump.Mode == 2) ReefAngel.LCD.DrawLargeText(COLOR_GOLD,255,25,26,"Reef Crest");
  else if (ReefAngel.DCPump.Mode == 3) ReefAngel.LCD.DrawLargeText(COLOR_CORNFLOWERBLUE,255,22,26,"Short Pulse");
  else if (ReefAngel.DCPump.Mode == 4) ReefAngel.LCD.DrawLargeText(COLOR_PINK,255,25,26,"Long Pulse");
  else if (ReefAngel.DCPump.Mode == 5) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,8,26,"Nutrient Trnsp.");
  else if (ReefAngel.DCPump.Mode == 6) ReefAngel.LCD.DrawLargeText(COLOR_MAGENTA,255,23,26,"Tidal Swell");
  else if (ReefAngel.DCPump.Mode == 9) ReefAngel.LCD.DrawLargeText(COLOR_WHITE,255,45,26,"Night");

  ReefAngel.LCD.DrawLargeText(0,255,17,36,"Display");
  ReefAngel.LCD.DrawLargeText(0,255,17,49,"Temp");
  ConvertNumToString(text, ReefAngel.Params.Temp[T1_PROBE], 10);
  ReefAngel.LCD.DrawHugeText(COLOR_RED, 255, 12, 65, text, Num12x16);
  pingSerial();

  ReefAngel.LCD.DrawLargeText(0,255,100,36,"pH");
  ConvertNumToString(text, ReefAngel.Params.PH, 100);
  ReefAngel.LCD.DrawLargeText(COLOR_BLUE, 255, 89, 55, text, Num8x8);
  pingSerial();
  
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,16,80, "Jebao");
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,16,89, "Left"); 
  ReefAngel.LCD.DrawText(COLOR_BLACK,255,16,100, ReefAngel.PWM.GetDaylightValue());
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,64,80, "Jebao");
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,64,89, "Center"); 
  ReefAngel.LCD.DrawText(COLOR_BLACK,255,38,100, ReefAngel.PWM.GetActinicValue());
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,96,80, "Jebao");
  ReefAngel.LCD.DrawText(COLOR_CORNFLOWERBLUE,255,96,89, " Right"); 
  ReefAngel.LCD.DrawText(COLOR_BLACK,255,96,100, ReefAngel.PWM.GetDaylightValue());

  pingSerial();
 
  
  
}
void DrawCustomGraph()
{
}



void SeasonalTemps ()
 {
  static int heatArray[][2] = { {780,785},// default in case of error in month=0 (June)
                    {770,774},//January (winter) 77.2
                    {774,778},//February (winter) 77.6
                    {775,779},//March (early spring) 77.7
                    {779,783},//April (spring) 78.1
                    {785,789},//May (spring) 78.7
                    {792,796},//June (early summer) 79.4
                    {799,803},//July (summer) 80.1
                    {806,810},//August (summer) 80.8
                    {796,800},//September (early fall) 79.8
                    {787,791},//October (fall) 78.9
                    {780,784},//November (fall) 78.2
                    {775,779} };//December (early winter) 77.7
                    
               
ReefAngel.StandardHeater(Port5,heatArray[month()][0],heatArray[month()][1]);
ReefAngel.StandardHeater(Box1_Port3,heatArray[month()][0],heatArray[month()][1]);
ReefAngel.StandardHeater(Box1_Port5,heatArray[month()][0],heatArray[month()][1]);
 }//end seasonalTemps



// RA_STRING2=null
// RA_STRING3=null


This works to turn them on but I can't figure out how to get them to go off after using lights off

Code: Select all

// Lights turned on set Blues to 50% and whites to 35%
{
if (bitRead(ReefAngel.StatusFlags,LightsOnFlag))
     ReefAngel.PWM.SetChannel( 1,(35) ); //Set Front Daylight 35%
     ReefAngel.PWM.SetChannel( 2,(50) ); //Set Front Actinics 50%
     ReefAngel.PWM.SetChannel( 3,(35) ); //Set Rear Daylight 35%
     ReefAngel.PWM.SetChannel( 4,(50) ); //Set Rear Actinics 50%
}
Post Reply