if else statement not turning off/on ports?

Do you have a question on how to do something.
Ask in here.

Posts: 51
Joined: Mon Nov 19, 2012 9:22 pm
PostPosted: Fri Oct 31, 2014 11:09 am
Can anyone tell me why this isn't working?

Code: Select all
if (hour()>22 && hour()<10) // between 10pm and 10am
{
ReefAngel.Relay.Off( tunze1 );
ReefAngel.Relay.Off( tunze2 );
} else {
ReefAngel.Relay.On( tunze1 );
ReefAngel.Relay.On( tunze2 );
}


Full code 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>
/*
// ports by name
*/

#define halide 1
#define actinics 2
#define uvlight 3
#define unused 4
#define jebao1 5
#define tunze1 6
#define doser1 7
#define doser2 8

#define ato Box1_Port1
#define heater1 Box1_Port2
#define skimmer Box1_Port3
#define heater2 Box1_Port4
#define jebao2 Box1_Port5
#define tunze2 Box1_Port6
#define gfo Box1_Port7
#define mainPump Box1_Port8

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


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


void setup()
{
// This must be the first line

// InternalMemory.LCDID_write(0);
ReefAngel.Init(); //Initialize controller

// Ports toggled in Feeding Mode
// mainPump, skimmer, tunzes, ato, gfo
// ReefAngel.FeedingModePorts = Port5Bit | Port6Bit;
ReefAngel.FeedingModePortsE[0] = Port1Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;

// Ports toggled in Water Change Mode
// mainPump, Skimmer, all 4 pumps, all 2 dosers, ato, gfo
ReefAngel.WaterChangePorts =  Port5Bit | Port6Bit | Port7Bit | Port8Bit;
ReefAngel.WaterChangePortsE[0] = Port1Bit | Port3Bit | Port5Bit | Port6Bit | Port7Bit | Port8Bit;

// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port1Bit | Port2Bit;
ReefAngel.LightsOnPortsE[0] = 0;

// Ports turned off when Overheat temperature exceeded
// metal halide, uv, tunze pumps,

ReefAngel.OverheatShutoffPorts = Port1Bit | Port3Bit;
ReefAngel.OverheatShutoffPortsE[0] = Port2Bit | Port4Bit | Port5Bit | Port6Bit;

// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;


// Ports that are always on
ReefAngel.Relay.On( mainPump );
ReefAngel.Relay.On( skimmer );
// ReefAngel.Relay.On( tunze1 );
// ReefAngel.Relay.On( tunze2 );
ReefAngel.Relay.On( jebao1 );
ReefAngel.Relay.On( jebao2 );
ReefAngel.Relay.On( gfo );
ReefAngel.Relay.On( uvlight );

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

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

void loop()
{
ReefAngel.DayLights( halide );
ReefAngel.ActinicLights( actinics );
ReefAngel.DosingPumpRepeat1( doser1 );
ReefAngel.DosingPumpRepeat2( doser2 );
// ReefAngel.StandardATO( ato );
ReefAngel.StandardHeater( heater1 );
ReefAngel.StandardHeater( heater2 );
ReefAngel.PWM.DaylightPWMParabola();
ReefAngel.PWM.ActinicPWMParabola();
////// Place your custom code below here

// set single ato

ReefAngel.SingleATO(true,ato,60,0);
if (ReefAngel.HighATO.IsActive()) ReefAngel.Relay.Off(ato);

ReefAngel.Relay.DelayedOn( skimmer );
ReefAngel.Relay.DelayedOn( gfo );

// turn off tunze when the lights go out

if (hour()>22 && hour()<10) // between 10pm and 10am
{
ReefAngel.Relay.Off( tunze1 );
ReefAngel.Relay.Off( tunze2 );
} else {
ReefAngel.Relay.On( tunze1 );
ReefAngel.Relay.On( tunze2 );
}


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

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

void DrawCustomMain()
{
int x,y;
char text[10];
// Parameters
#if defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 62, ReefAngel.Params,
ReefAngel.PWM.GetDaylightValue(), ReefAngel.PWM.GetActinicValue() );
#else // defined DisplayLEDPWM && ! defined RemoveAllLights
ReefAngel.LCD.DrawMonitor( 15, 62, ReefAngel.Params );
#endif // defined DisplayLEDPWM && ! defined RemoveAllLights
pingSerial();

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

// Relay Expansion
TempRelay = ReefAngel.Relay.RelayDataE[0];
TempRelay &= ReefAngel.Relay.RelayMaskOffE[0];
TempRelay |= ReefAngel.Relay.RelayMaskOnE[0];
ReefAngel.LCD.DrawOutletBox( 12, 107, TempRelay );
pingSerial();

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

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

Posts: 12288
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri Oct 31, 2014 11:24 am
&& means AND
It will never happen.
Time can't be >22 AND < 10 at the same time.
Change it to ||, which means OR
Roberto.

Posts: 51
Joined: Mon Nov 19, 2012 9:22 pm
PostPosted: Fri Oct 31, 2014 12:20 pm
oh man, i should have caught that.

thanks roberto
User avatar
Posts: 5361
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Oct 31, 2014 12:28 pm
Because you can't have a condition where the hour is BOTH greater than 22 AND less then 10.

Change the && to ||

&& = AND
|| = OR

Return to How do I code ...

Who is online

Users browsing this forum: No registered users and 2 guests