so I am running a single ATO switch setup and what I have found is that sometimes the switch will bounce trigger on/off/on/off etc.. This does not happen every single time.
I was hoping to implement a minimum amount of time the Controller has to wait between cycling the ATO Relay port on.
Example it turns on then turns off... no matter what the switch does, the controller has to wait lets say, one hour before listening to the switch and turning the ATO Relay on.
Here is my 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 <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 | Port6Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port3Bit | Port4Bit | Port5Bit | Port7Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port3Bit | Port4Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port1Bit | Port4Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
// Set the Overheat temperature setting
InternalMemory.OverheatTemp_write( 825 );
// Feeeding and Water Change mode speed
ReefAngel.DCPump.FeedingSpeed=0;
ReefAngel.DCPump.WaterChangeSpeed=0;
// Ports that are always on
ReefAngel.Relay.On( Port5 );
ReefAngel.Relay.On( Port6 );
////// Place additional initialization code below here
////// Place additional initialization code above here
}
void loop()
{
ReefAngel.StandardHeater( Port1,777,780 );
ReefAngel.StandardLights( Port2,21,30,12,0 );
ReefAngel.StandardLights( Port3,12,0,21,30 );
ReefAngel.MHLights( Port4,14,0,20,30,5 );
ReefAngel.SingleATO( true,Port7,4542,0 );
ReefAngel.StandardLights( Port8,12,0,21,45 );
////// Place your custom code below here
if (hour()>=11 && hour()<20) // 11am - 8pm
{
ReefAngel.PWM.SetDaylight( ElseMode(65,20,true) ); // ReefCrest at 65% +/- 20% on sync mode
}
else if (hour()>=20 && hour()<23) // 8pm - 11pm
{
ReefAngel.PWM.SetDaylight( NutrientTransportMode(30,90,500,true) ); // Nutrient Transport 30%minspeed - 90%maxspeed - 500ms
}
else if (hour()>=23 || hour()<11) // 11pm - 11am
{
ReefAngel.PWM.SetDaylight( ElseMode(40,15,true) ); // ReefCrest at 40% +/- 15% on sync mode
}
////// Place your custom code above here
// This should always be the last line
ReefAngel.Portal( "ReEfnWrX" );
ReefAngel.ShowInterface();
}
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;
}
}